I am making a SOAP web service in PHP that must meet the requirements of a client XSD file.
Here is the link to the XSD file provided by the client: http://pastebin.com/MX1BZUXc
The expected answer is as follows:
[Some long lines are broken down into legibility, into the theory that the problem is not related to spaces.]
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header /> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <CheckVersionResponse xmlns="http://www.---.---/---"> <CheckversionResult> <ValidationOk>true</ValidationOk> <VersionNumber>1.4.0</VersionNumber> <CurrentRemoteServerTime >2014-05-02T09:35:20.368+02:00</CurrentRemoteServerTime> </CheckversionResult> </CheckVersionResponse> </s:Body> </s:Envelope>
However, the answer I am getting now is as follows:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://---.---/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"> <env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"> <ns1:CheckVersionResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> <rpc:result>return</rpc:result> <return xsi:type="enc:Struct"> <ValidationOk xsi:type="xsd:int">1</ValidationOk> <VersionNumber xsi:type="xsd:string" >1.4.0</VersionNumber> <CurrentRemoteServerTime xsi:type="xsd:string" >2014-05-08T10:31:49</CurrentRemoteServerTime> </return> </ns1:CheckVersionResponse> </env:Body> </env:Envelope>
Here's how I made my SOAP web service:
<?php class CheckVersionResult extends stdClass { public $ValidationOk = ''; public $VersionNumber = ''; public $CurrentRemoteServerTime = ''; } class MySoapClass { public function CheckVersion($param1, $param2) { $data = new CheckVersionResult(); $data->ValidationOk = 1; $data->VersionNumber = '1.4.0'; $data->CurrentRemoteServerTime = date('Ymd\TH:i:s'); } } class WebserviceController { public function indexAction() { $soap = new Zend_Soap_Server(); $soap->setClass('MySoapClass'); $soap->setUri("http://---.---/"); $mySoapClass = new MySoapClass(); $soap->setObject($mySoapClass); $soap->setSoapVersion(SOAP_1_2); $soap->handle(); } }
And here is what I call my web service:
$client = new SoapClient(null, array( "soap_version" => SOAP_1_2, "location" => "http://---.---/webservice/index", "uri" => "http://---.---/", "trace" => 1, // enable trace to view what is happening "exceptions" => 0, // disable exceptions "cache_wsdl" => 0) // no wsdl ); $client->CheckVersion('param1', 'param2'); header('Content-Type: application/xml; charset=utf-8'); echo $client->__getLastResponse(); die();
Does anyone know how I can properly format my SOAP response according to the XSD file I received?