-
Bug
-
Resolution: Fixed
-
Minor
-
2.8.3, 2.8.5
-
MOODLE_28_STABLE
-
MOODLE_28_STABLE, MOODLE_29_STABLE
-
MDL-49560-master -
- Set up web serices using SOAP, create user with token
- Make sure user has all appropriate permissions including using soap (webservice/soap:use)
- Test any web service using SOAP with and without token
Test on moodle 2.8.5+
Tried to use web services protocol SOAP.
Configure moodle web service as described in the documentation (https://docs.moodle.org/28/en/Using_web_services).
Created a web service client, as shown here: https://docs.moodle.org/dev/Creating_a_web_service_client
WSDL was not created automatically, SoapClient generated an error:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/moodle/webservice/soap/server.php?wsdl=1&wstoken=af881bc315aae584f8f20f106b5d4075' : failed to load external entity "http://localhost/moodle/webservice/soap/server.php?wsdl=1&wstoken=af881bc315aae584f8f20f106b5d4075" in D:\server\home\localhost\www\index.php on line 73
After this I change value NO_DEBUG_DISPLAY to false (/webservice/soap/server.php on line 29). Script gave me an error:
Fatal error: Cannot redeclare class webservices_struct_class_000027 in D:\server\home\moodle.pgtu\www\webservice\soap\locallib.php(300) : eval()'d code on line 5
This error occurs due to the use of recursion in the file /webservice/soap/locallib.php on line 285 and calls method get_phpdoc_type($fieldsdesc). Incremented previously webservices_struct_class_000000 class name is overwritten with a new value as a result of calling this method, and when you try to create a new class with the same name, the script gives an error.
To get rid of this error, you need to swap the check for the generated class and calling get_phpdoc_type
New code of method:
/**
- Generate 'struct' type name
- This type name is the name of a class generated on the fly.
* - @param external_single_structure $structdesc
- @return string
*/
protected function generate_simple_struct_class(external_single_structure $structdesc) {
global $USER;
$fields = array();
foreach ($structdesc->keys as $name => $fieldsdesc)
// let's use unique class name, there might be problem in unit tests
$classname = 'webservices_struct_class_000000';
while(class_exists($classname))
$code = '
/**
- Virtual struct class for web services for user id '.$USER->id.' in context '.$this->restricted_context->id.'.
*/
class '.$classname.' { '.implode("\n", $fields).' }';
eval($code);
return $classname;
}