webservice response according to wsdl

webservice response according to wsdl

by Attila Peto -
Number of replies: 1

hi!

is there a way to tell moodle webservice to use a specific wsdl file while generating response?

moodle generates the following code whitout wsdl  (snippet)

<ns1:mn_resultWritebackResponse>
<return xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">usernames</key>
<value SOAP-ENC:arrayType="xsd:string[2]" xsi:type="SOAP-ENC:Array">
<item xsi:type="xsd:string">user1</item>
<item xsi:type="xsd:string">user2</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">secret</key>
<value xsi:type="xsd:string">hash</value>
</item>
</return>
</ns1:mn_resultWritebackResponse>

and do this way for any array output.

but I want something like this:

 

<ns1:mn_resultWritebackResponse>
<usernames xsi:type="ns1:usernameList">
<username xsi:type="xsd:string">user1</username>
<username xsi:type="xsd:string">user2</username>
</usernames>
<secret xsi:type="xsd:string">hash</secret>
</ns1:mn_resultWritebackResponse>


which is generated automatically if I enter wsdl file location in lib/Zend/Soap/Server.php line 167:

$wsdl='location/to/wsdl/file.wsdl';

I know that Zend_Soap_Server allow to set wsdl with it's method setWsdl(), but I cannot find any settings in moodle, or any possibility in the webservice 'external_api' and in it's methods.

This option could be set somewhere in webserivce/lib.php line 698, in the public function run, where the zend_soap_server is initalized, if the function or the class (webservice_zend_server and it's derivatives) itself would have such options.e

 

the corresponding wsdl snippet:

 

...
<xsd:complexType name="usernameList">
<xsd:sequence>
<xsd:element name="username" type="xsd:string"
maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
...
<wsdl:message name="resultWritebackResponse">
<wsdl:part name="secret" type="xsd:string" />
<wsdl:part name="usernames" type="tns:usernameList" />
</wsdl:message>
...


and the external_api's _returns() function:

 

public static function resultWriteback_returns() {

return new external_single_structure(
array('usernames'=>
new external_multiple_structure (
new external_value(PARAM_TEXT,'username')),
'secret'=>new external_value(PARAM_TEXT,'secret')
)
);
}


Any idea? thanks!

 

Attila

Average of ratings: -
In reply to Attila Peto

Re: webservice response according to wsdl

by Troy Williams -
Picture of Plugin developers

Hi Attila,

I am having similar problem, as I need to output a document/literal wrapped response. I have very little experience here and it is making my head hurt. sleepy I have setup web service based on MoodleDoc: Development:Creating a web service and a web service function.  Looking at files webservice/lib.php and webservice/soap/locallib.php you will have to hack those files or write your own class and from there pass in the location of wsdl file. Unsure how entirely works but a virtual class is created and methods that you created in your externallib.php are used in that virtual class.  I will keep investigating...

Regards,

Troy