Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

SOAP web service implementation classes and methods.

Copyright: 2009 Petr Skodak
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 337 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

webservice_soap_server:: (9 methods):
  __construct()
  parse_request()
  run()
  generate_wsdl()
  handle()
  send_error()
  send_response()
  send_headers()
  fault()

webservice_soap_test_client:: (1 method):
  simpletest()


Class: webservice_soap_server  - X-Ref

SOAP service server implementation.

__construct($authmethod)   X-Ref
Contructor.

param: string $authmethod authentication method of the web service (WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN, ...)

parse_request()   X-Ref
This method parses the $_POST and $_GET superglobals and looks for the following information:
- User authentication parameters:
- Username + password (wsusername and wspassword), or
- Token (wstoken)


run()   X-Ref
Runs the SOAP web service.


generate_wsdl()   X-Ref
Generates the WSDL.


handle()   X-Ref
Handles the web service function call.


send_error($ex = null)   X-Ref
Send the error information to the WS client formatted as an XML document.

param: Exception $ex the exception to send back

send_response()   X-Ref
Send the result of function call to the WS client.


send_headers()   X-Ref
Internal implementation - sending of page headers.


fault($fault = null, $code = 'Receiver')   X-Ref
Generate a server fault.

Note that the parameter order is the reverse of SoapFault's constructor parameters.

Moodle note: basically we return the faultactor (errorcode) and faultdetails (debuginfo).

If an exception is passed as the first argument, its message and code
will be used to create the fault object.

param: string|Exception $fault
param: string $code SOAP Fault Codes

Class: webservice_soap_test_client  - X-Ref

SOAP test client class

simpletest($serverurl, $function, $params)   X-Ref
Execute test client WS request

return: mixed
param: string $serverurl server url (including token parameter or username/password parameters)
param: string $function function name
param: array $params parameters of the called function