2

I am having difficulty getting started with interfacing my PHP script to Moodle 2.0 over the SOAP Web Service provided. Not knowing much about SOAP, I figured I would simply connect and go from there. However, I can't even get connected...

$soap=new SoapClient(
    'http://mymoodleserver/webservice/xmlrpc/server.php?wstoken=asdfasdfasdfasdfasdf',
    array(
        'trace'=>1,
        'exceptions'=>true,
        'cache_wsdl'=>WSDL_CACHE_NONE
    )
);

This returns:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load...

If I were to go to this URL directly, no data is returned. Looking at it with Fiddler shows that the server does indeed return a Content-Length of 0.

There isn't any documentation on this that I could find... there is documentation for other protocols however.

I am assuming that the SoapClient is expecting some WSDL to define what functions are available. I have a list of those functions and parameters (no thanks to the official documentation page). How can I instruct SoapClient to not worry about the WSDL and carry on?

I have checked for errors in the PHP error log on the Moodle server, and it turned up clean.

hakre
  • 193,403
  • 52
  • 435
  • 836
Brad
  • 159,648
  • 54
  • 349
  • 530

2 Answers2

1

The way to use the non wsdl mode is to add it to the uri

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));

Ofocurse, use trace and then look for getlastrequest and getlastresponse

$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";

http://www.php.net/manual/en/soapclient.getlastrequest.php

Use xmlspy for easy debugging.

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
pal4life
  • 46
  • 2
0

The key is in the error, so I started looking at the documentation for Moodle knowing what to expect, no WSDL.

Check the documentation for SoapClient and the documentation for Moodle as you can see Moodle doesnt offer WSDL so you need to use the SoapClient in non-WSDL mode.

Kristoffer Sall-Storgaard
  • 10,576
  • 5
  • 36
  • 46