The Moodle LMS can be used to quiz students. One optional question type (Opaque) uses SOAP to request questions from a service ( code at https://goo.gl/iGDIiy ).
There is a working "question server" implemented in PHP using the WSDL defined at https://goo.gl/kESENq
The complication that I am running into is that the code in the question type expected some return values to be a string. The response from the functioning test server looks like...
<SOAP-ENV:Body>
<ns1:getEngineInfoResponse>
<getEngineInfoReturn xsi:type="SOAP-ENC:string">
<engineinfo>
Note the xsi:type=..string. The data is actually returned as an XML formatted string by the PHP application:
/**
* A dummy implementation of the getEngineInfo method.
* @return string of XML.
*/
public function getEngineInfo() {
return '<engineinfo>
I'm trying to interface this to a Python+SOAP server. I've tried using both ZSI and Spyne. With ZSI, I used the WSDL provided with the sample server to generate the code stubs. The corresponding code simply returns a string much like the PHP code. The response from that is:
<ns1:getEngineInfoResponse>
<getEngineInfoReturn>
<engineinfo>
Note the lack of the string type modifier. This response gets received by the PHP code in Moodle as an object containing a single field with no name but containing the returned XML string. Because it's an object containing a string, rather than just a string, the code fails to parse the result correctly.
With Spyne, I get:
soap11env:Body>
<tns:getEngineInfoResponse>
<tns:getEngineInfoReturn><engineinfo>
from this code:
@srpc(_returns=String, _body_style='wrapped',
_out_variable_name="getEngineInfoReturn"
)
def getEngineInfo():
resp = "<engineinfo>\n"
This also returns an object with a single element (now named getEngineInfoReturn) that contains the appropriate string. However, the receiver (which was happy with the WSDL produced) still expects a string and not an object containing a string.
I'd rather get the Spyne version working than the ZSI version because it's easier to use. I've used SOAP before, but am not certain if the PHP code is making an unwarranted assumption about the return format or if I should be able to torque Spyne into producing that format. From reading the source code for the decorator function, I don't think I can.
So, is this a poorly coded client or is the expected SOAP schema normal? How can I get Spyne (or ZIS) to produce something similar?
Pass _out_body_style='bare'
to @rpc.