-
Notifications
You must be signed in to change notification settings - Fork 19
Using oktech ws with moodle 2.0 official web service infrastructure
Historically, OKTech WS was created as a contributed plugin and was not meant at all to be called from Moodle core API. Back in 2007, there was no official Web Services in Moodle core and the concept of 'local plugin' was not well documented.
It is now possible to use OKTech in two ways, eventually simultaneously :
The historical way, based on a standard WSDL, recognized by most programming languages (java, python, php...). In the way, SOAP clients consult the current WSDL (available at http://yourmoodle/wspp/wsdl_pp2.php) to build a stub to access the available operations and several helper classes to marshall input and output datatypes. And in REST mode, operations are directly available by a call to http://yourmoodle/wspp/service_pp2.php with the appropriate HTTP parameters (at least wsfunctionname, wsformatout are required). In both cases the normal workflow is to call :
-
first : the login operation, with a login/password pair , that will return a couple id/sessionkey.
-
then one or more operation, sending back the couple id/sessionkey plus the parameters required by that operation
-
finally a call to operation logout , the 'close the session'.
-
alternatively in REST mode, the target operation can be directly called (in 'singleshot mode') by supplying a valid wsusername/wspassword pair of extra parameters.
It is now possible to include most(*) of the OK Tech operations to the list of functions available under the new Moodle 2.0 Web Services infrastructure. In that case the historical login/logout mechanism of OKTech is bypassed and authentication must be performed by the Moodle 2.0 way, that is by sending either an wsusername/wspassword couple or a wstoken value to Moodle 2.0 Web Service entry points :
-
in REST either http://yourmoodle/webservice/rest/simpleserver.php (standard mode)
-
or http://yourmoodle/webservice/rest/server.php (token mode)
-
in SOAP either http://yourmoodle/webservice/soap/simpleserver.php (standard mode)
-
or http://yourmoodle/webservice/soap/server.php (token mode)
First make sure that Moodle 2.0 official WS is installed properly and running on your Moodle installation. With Moodle 2.0.3, you should see in Site administration/ Web services the list of current functions (prefixed as moodle_xxxxx) and be able to test them.
Of course install OK Tech as described in the INSTALLATION file (don't forget to copy wspp/local/wspp to Moodle 2.0 local folder) .
Now copy wspp/moodle2integration/oktech folder into the local folder of your Moodle installation. You should see something like :
local
|-- oktech
| |-- db
| | |-- services.php
| |-- externallib.php
| |-- oktech_classeslib.php
| |-- version.php
|-- readme.txt
`-- wspp
|-- db
| `-- install.xml
|-- lang
| |-- en
| | `-- local_wspp.php
| `-- fr
| `-- local_wspp.php
|-- settings.php
`-- version.php
Now visit Site Administration, then Notifications . This should start the update wizard and produces the output 'oktech '... Success and the continue Button.
All the functions of OKTech has been added to Moodle 2.0 Web Service and should appear under Site Administration/ Plugins/ Web Services under a new service named 'oktech WS'. You will notice that the functions have the same names as the 'historical operations', but prefixed with 'oktech_'.
- Limited WSDL emission : Moodle 2.0 WS has a limited support for WSDL but the returned data is not complete enough for automatic clients generation in languages such as Java or python. The WSDL do contains all operations and messageIn messageOut structures, so the stub is properly built, but all datatypes are returned as simple arrays, so no helper classes can be generated. See http://tracker.moodle.org/browse/MDL-20804
To experiment with current WSDL generation using PHP you may try the following script :
<?php
$moodleWebserviceUrl="http://yourmoodle/webservice/soap/simpleserver.php";
$moodleToken='somelogin';
$moodlePassword='somepassword';
$client = new SoapClient($moodleWebserviceUrl . '?wsusername=' . $moodleToken .'&wspassword='.$moodlePassword. '&wsdl=1');
print_r($client->__getFunctions());
?>and should get something like :
Array
(
[0] => Array moodle_group_create_groups(Array $groups)
[1] => Array moodle_group_get_groups(Array $groupids)
[2] => void moodle_group_delete_groups(Array $groupids)
[3] => Array moodle_group_get_groupmembers(Array $groupids)
[4] => void moodle_group_add_groupmembers(Array $members)
[5] => void moodle_group_delete_groupmembers(Array $members)
[6] => Array moodle_user_create_users(Array $users)
[7] => void moodle_user_delete_users(Array $userids)
[8] => void moodle_user_update_users(Array $users)
[9] => Array moodle_group_get_course_groups(int $courseid)
[10] => UNKNOWN moodle_file_get_files(int $contextid, string $component, string $filearea, int $itemid, string $filepath, string $filename)
[11] => UNKNOWN moodle_file_upload(int $contextid, string $component, string $filearea, int $itemid, string $filepath, string $filename, string $filecontent)
[12] => Array moodle_user_get_users_by_id(Array $userids)
[13] => Array moodle_enrol_get_enrolled_users(int $courseid, string $withcapability, int $groupid, int $onlyactive)
[14] => void moodle_role_assign(Array $assignments)
[15] => void moodle_role_unassign(Array $unassignments)
[16] => Array moodle_course_get_courses(UNKNOWN $options)
[17] => Array moodle_course_create_courses(Array $courses)
[18] => Array oktech_add_assignment(UNKNOWN $datum)
[19] => Array oktech_add_category(UNKNOWN $datum)
[20] => Array oktech_add_cohort(UNKNOWN $datum)
[21] => Array oktech_add_course(UNKNOWN $coursedatum)
[22] => Array oktech_add_database(UNKNOWN $datum)
[23] => Array oktech_add_forum(UNKNOWN $datum)
[24] => Array oktech_add_group(UNKNOWN $datum)
[25] => Array oktech_add_grouping(UNKNOWN $datum)
[26] => Array oktech_add_label(UNKNOWN $datum)
[27] => UNKNOWN oktech_add_noneditingteacher(string $courseid, string $courseidfield, string $userid, string $useridfield)
[28] => Array oktech_add_pagewiki(UNKNOWN $datum)
[29] => Array oktech_add_section(UNKNOWN $datum)
[30] => UNKNOWN oktech_add_student(string $courseid, string $courseidfield, string $userid, string $useridfield)
[31] => UNKNOWN oktech_add_teacher(string $courseid, string $courseidfield, string $userid, string $useridfield)
[32] => Array oktech_add_user(UNKNOWN $userdatum)
[33] => Array oktech_add_wiki(UNKNOWN $datum)
[34] => UNKNOWN oktech_affect_assignment_to_section(int $assignmentid, int $sectionid, int $groupmode)
[35] => UNKNOWN oktech_affect_course_to_category(int $courseid, int $categoryid)
...
[160] => Array oktech_update_group(UNKNOWN $datum, string $idfield)
[161] => Array oktech_update_grouping(UNKNOWN $datum, string $idfield)
[162] => Array oktech_update_section(UNKNOWN $datum, string $idfield)
[163] => Array oktech_update_user(UNKNOWN $datum, string $useridfield)
)As you can see the exchanged datatypes are not properly sent.
Our utility wsdl2php.php does produces some useful output when called as below :
php wsdl2php.php 'http://yourmoodle20/webservice/soap/simpleserver.php?wsusername=xxxx&wspassword=xxxx&wsdl=1' nologin
- Note the simple quotes that are required around the URL at the command line to avoid shell interpretation of & and the second parameter 'nologin' to avoid generation of standard OKTech login/logout prologue and epilogue in testing codes.
See https://github.com/moodlehq/sample-ws-clients for sample clients mostly in php for all protocols (soap, rest, xml-rpc ...)
To generate automatically the skeleton of nested parameters for all published operations, see my script at http://tracker.moodle.org/browse/CONTRIB-3472