php's Soap Client doesn't work but Boomerang tester does

php's Soap Client doesn't work but Boomerang tester does

by Doug Stevens -
Number of replies: 1

Ok, this is a weird one - and only seems to be impacting one method.  I'm using a PHP7.4 CLI script to add users from our SIS to moodle courses using enrol_manual_enrol_users.  Putting the following 

array(1991) {

 [0]=>
array(3) {
["userid"]=>
int(39615)
["courseid"]=>
int(500)
["roleid"]=>
int(5)
}
[1]=>
array(3) {
["userid"]=>
int(23782)
["courseid"]=>
int(500)
["roleid"]=>
int(5)
}
[2]=>
array(3) {
["userid"]=>
int(10057)
["courseid"]=>
int(500)
["roleid"]=>....

into $registerarray and running  

$clientm->enrol_manual_enrol_users($registerarray);

Where $clientm is an instance of soapClient, happily returns a 200 but shows on the moodle side as "The web service function 'unknown' has been called." and of course nobody enrolled.

Now, here is where things get weird. With tracing on I called 

var_dump($clientm->__getLastRequest());

and then copy/pasted the xml output into the Boomerang api workspace

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns:env="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns1="https://********/webservice/soap/server.php?wstoken=**************************"
xmlns:ns2="http://xml.apache.org/xml-soap"
xmlns:enc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<ns1:enrol_manual_enrol_users env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<enrolments enc:itemType="ns2:Map" enc:arraySize="1991" xsi:type="enc:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">userid</key>
<value xsi:type="xsd:int">39615</value>
</item>
<item>
<key xsi:type="xsd:string">courseid</key>
<value xsi:type="xsd:int">500</value>
</item>
<item>
<key xsi:type="xsd:string">roleid</key>
<value xsi:type="xsd:int">5</value>
</item>
</item>
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">userid</key>
<value xsi:type="xsd:int">23782</value>
</item>
<item>
<key xsi:type="xsd:string">courseid</key>
<value xsi:type="xsd:int">500</value>
</item>
<item>
<key xsi:type="xsd:string">roleid</key>
<value xsi:type="xsd:int">5</value>
...



 and it worked perfectly, returning a 202 and students enrolled. I thought it might be headers, but other methods in the same script worked.
I'd love any ideas anyone may have!

Thanks in advance
Doug

Average of ratings: -
In reply to Doug Stevens

Re: php's Soap Client doesn't work but Boomerang tester does

by Doug Stevens -

Solved, and the solution was related to soapClient class headers. It wasn't waiting for a response from the server before moving on as it processed the enrol_manual_enrol_users asynchronously. I added 'features'=>SOAP_WAIT_ONE_WAY_CALLS, to the options and presto, everything worked!


$clientm = new SoapClient ($wsdlm, array (
'encoding' => 'UTF-8' ,
'cache_wsdl' => WSDL_CACHE_MEMORY,
'compression'=> SOAP_COMPRESSION_ACCEPT|SOAP_COMPRESSION_GZIP,
'soap_version'=>SOAP_1_2,
'keep_alive'=>true,
'exceptions'=>true,
'features'=>SOAP_WAIT_ONE_WAY_CALLS,
'trace'=>true
) );