Calling Moodle functions from PHP over SOAP

By : Brad
Source: Stackoverflow.com
Question!

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.

By : Brad


Answers

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.



This video can help you solving your question :)
By: admin