Resolution: Not a bug
Affects Version/s: 2.2
Fix Version/s: None
Component/s: Web Services
I have Moodle 2.2 running on a Linux host, and tried installing the wstemplate plugin that demonstrates how to implement a "Hello World" Web-service function. I then tried calling it from my PC. I did so by following the instructions at http://moodle.org/plugins/pluginversion.php?id=401 and in the client.php file that the plugin contains. This is what I did:
1. I downloaded the plugin from http://moodle.org/plugins/pluginversion.php?id=401
by clicking on the orange "Download for Moodle 2.0/Moodle 2.1/Moodle 2.2" box.
2. The download arrived as a zip file. I copied it into Moodle's local directory. Incidentally, this is /var/www/moodle/moodle/local .
3. I unzipped the zip file there. This created a subdirectory named 'wstemplate'
containing client, db, externallib.php, lang, README, and version.php .
4. From there, I copied local/wstemplate/client/client.php and curl.php
onto my PC.
5. I edited client.php to make $token a token I'd already created, and that I know works in a program that calls the built-in Web services
(the program at http://moodle.org/mod/forum/discuss.php?d=193295&parent=841702 ). And so that $domainname was my Moodle's URL. I checked that the token was still valid, by running my demo of the built-in Web services. It worked.
6. On Moodle, I went to Site administration > Notifications. This
gave me a table of three plugins, the final one of which had this
Web service template /local/wstemplate Extension 2011101202 Moodle 2010112400 To be installed .
I pressed the 'Upgrade' button below the table. This brought up a page
I pressed the 'Continue' button on it. This brought up a blank Notifications
7. I went to Site administration > Advanced features, and
checked that the "Enable web services" checkbox was
8. I went to Site administration > Plugins > Web services > Manage protocols,
and checked that the checkbox for XML-RPC protocol was ticked.
(So, by the way, was that for REST protocol. This is relevant to another problem I mention.)
9. I went to Site administration > Plugins > Web services > External services.
This showed a table with the line
My service local_wstemplate Functions All users Edit .
So the service had evidently been installed. Clicking on "Functions"
showed another table saying
local_wstemplate_hello_world Return Hello World FIRSTNAME.
Can change the text (Hello World)
sending a new text as parameter
That concluded the installation instructions at the top
of client.php .
10. On my PC, I ran client.php by giving the DOS command
php client.php .
But I got this response:
[faultCode] => 620
[faultString] => Method "local_wstemplate_hello_world" does not exist
Perhaps I have missed out some installation or configuration step, but the documentation doesn't tell me to do anything else. So if I have, there may be a bug in the documentation.
I also tried calling local_wstemplate_hello_world via REST, in the same way as I called the built-in functions in my demo program. I did so using this PHP code:
echo "Demo of Web service Hello World\n";
$token = '5c3510bdd288c1039228fad9ae5da';
$domain = 'http://moodle.ireson-paine.com';
$welcomemsg = 'Hello, ';
$function_name = 'local_wstemplate_hello_world';
$params = array( $welcomemsg );
$serverurl = $domain . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$function_name;
require_once( './curl.php' );
$curl = new curl;
echo "\nAbout to call function.\n";
$response = $curl->post( $serverurl, $params );
echo "\nCalled function.\n";
echo "\nResponse = $response.\n";
This gave me the following error:
Response = <?xml version="1.0" encoding="UTF-8" ?>
<MESSAGE>Access control exception</MESSAGE>
<DEBUGINFO>Access to the function local_wstemplate_hello_world() is not allowed
Please check if a service containing the function is enabled. In the service s
ttings: if the service is restricted check that the user is listed. Still in th
service settings check for IP restriction or if the service requires a capabil
I think the service containing the function is enabled, because the 'Enabled' checkbox is ticked on Site administration ► Plugins ► Web services ► External services ► External service. It is not restricted, but is open to all users. It has no IP restrictions, and does not need a capability. So the above error message may also be wrong, or at least less informative than it should be.