|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-09-15 13:33 UTC] matteo dot veggia at gmail dot com
Description: ------------ I will be short: i have an WCF in a IIS Windows Server. This WCF host a web service with this function: public Dictionary<string, string> TestRoutine(Dictionary<string, string> Data) I calling this function with PHP with these rows: $url = "http://testserver/test/test.svc?wsdl"; $soapClient = new SoapClient($url, array('cache_wsdl' => WSDL_CACHE_NONE) ); $argsSOAP = new StdClass(); $argsSOAP->Data = Array(); array_push($argsSOAP->Data, Array("Key"=>"A", "Value"=>"1")); array_push($argsSOAP->Data, Array("Key"=>"B", "Value"=>"2")); $resSOAP = $soapClient->TestRoutine($argsSOAP); print_r($resSOAP); In PHP 5.6.X these rows works! In PHP 7.0.11 NO! The "Data" parameter result empty BUT If I put the values into the dictionary with a direct assignment, not using "array_push": $url = "http://testserver/test/test.svc?wsdl"; $soapClient = new SoapClient($url, array('cache_wsdl' => WSDL_CACHE_NONE) ); $argsSOAP = new StdClass(); $argsSOAP->Data = Array(); $argsSOAP->Data[0] = Array("Key"=>"A", "Value"=>"1"); $argsSOAP->Data[1] = Array("Key"=>"B", "Value"=>"2"); $resSOAP = $soapClient->TestRoutine($argsSOAP); print_r($resSOAP); IT WORKS!!! Why? Can you check? My PHP application is all based with array_push. Please help Thanks Matteo V. Test script: --------------- $url = "http://testserver/test/test.svc?wsdl"; $soapClient = new SoapClient($url, array('cache_wsdl' => WSDL_CACHE_NONE) ); $argsSOAP = new StdClass(); $argsSOAP->Data = Array(); array_push($argsSOAP->Data, Array("Key"=>"A", "Value"=>"1")); array_push($argsSOAP->Data, Array("Key"=>"B", "Value"=>"2")); $resSOAP = $soapClient->TestRoutine($argsSOAP); print_r($resSOAP); PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 06:00:01 2025 UTC |
This is the param encoding I get on PHP 7.0.12: <param0 xsi:type="SOAP-ENC:Struct"> <Data SOAP-ENC:arrayType="ns2:Map[2]" xsi:type="SOAP-ENC:Array"> <item xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">Key</key> <value xsi:type="xsd:string">A</value> </item> <item> <key xsi:type="xsd:string">Value</key> <value xsi:type="xsd:string">1</value> </item> </item> <item xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">Key</key> <value xsi:type="xsd:string">B</value> </item> <item> <key xsi:type="xsd:string">Value</key> <value xsi:type="xsd:string">2</value> </item> </item> </Data> </param0> Not knowing anything about SOAP specifically, it looks correct to me. Are you sure you are running PHP 7.0.12?The issue persists with PHP Version 7.0.13! I rewrite my code to remake the question simplified: $url = "wwwp.example.com/hello.svc?wdsl"; $options = Array("trace"=>1); //FIRST METHOD!!! (not working) $soapClient = new SoapClient($url, $options); $argsSOAP = new StdClass(); $argsSOAP->Data = Array(); array_push($argsSOAP->Data, Array("Key"=>"A", "Value"=>"1")); array_push($argsSOAP->Data, Array("Key"=>"B", "Value"=>"2")); $resSOAP = $soapClient->TestRoutineDictionary($argsSOAP); echo "REQUEST:<br>" . htmlspecialchars(str_ireplace('><', ">\n<", $soapClient->__getLastRequest())) . "<br>"; echo "Response:<br>" . htmlspecialchars(str_ireplace('><', ">\n<", $soapClient->__getLastResponse())) . "<br>"; echo "\n\n<hr>\n\n"; //SECOND METHOD (working...) $soapClient2 = new SoapClient($url, $options); $argsSOAP2 = new StdClass(); $argsSOAP2->Data = Array(); $argsSOAP2->Data[0] = Array("Key"=>"A", "Value"=>"1"); $argsSOAP2->Data[1] = Array("Key"=>"B", "Value"=>"2"); $resSOAP2 = $soapClient2->TestRoutineDictionary($argsSOAP2); echo "REQUEST:<br>" . htmlspecialchars(str_ireplace('><', ">\n<", $soapClient2->__getLastRequest())) . "<br>"; echo "Response:<br>" . htmlspecialchars(str_ireplace('><', ">\n<", $soapClient2->__getLastResponse())) . "<br>"; I execute this script with php.exe (without apache!) The results are different! In the first result is missing "http://schemas.microsoft.com/2003/10/Serialization/Arrays"... Please help me. MatteoI've found another element which it can explain more considerations: If I use $argsSOAP->Data = Array(); array_push($argsSOAP->Data, Array("Key"=>"A", "Value"=>"1")); array_push($argsSOAP->Data, Array("Key"=>"B", "Value"=>"2")); $resSOAP = $soapClient->TestRoutineDictionary($argsSOAP); the XML is wrong (read last posts). BUT... if I use a "support" variable called "tmparr": $tmparr = Array(); array_push($tmparr, Array("Key"=>"A", "Value"=>"1")); array_push($tmparr, Array("Key"=>"B", "Value"=>"2")); $argsSOAP->Data = $tmparr; $resSOAP = $soapClient->TestRoutineDictionary($argsSOAP); IT WORKS!!! Simple question... why?php code: $server = new SoapServer('my.wsdl'); $server->setClass(Api::class); $server->handle(); class Api { public function receiveEDIMessages() { return array( 'head' => null, 'body' => array( 'message' => 'text', 'from' => '2352457999993', 'to' => '2352456999994', 'id' => 54370 ), ); } } WSDL (use rpc style): <xsd:complexType name="bodyMessagesResponse"> <xsd:complexContent> <xsd:restriction base="soapenc:Array"> <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="tns:messageResponse[]"/> </xsd:restriction> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="messageResponse"> <xsd:sequence> <xsd:element name="message" type="xsd:string"/> <xsd:element name="from" type="xsd:string"/> <xsd:element name="to" type="xsd:string"/> <xsd:element name="id" type="xsd:integer"/> </xsd:sequence> </xsd:complexType> response php 5.6: <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http_://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http_://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:interface" xmlns:xsd="http_://www.w3.org/2001/XMLSchema" xmlns:xsi="http_://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:private" xmlns:SOAP-ENC="http_://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:receiveEDIMessagesResponse> <receiveEDIMessagesReturn xsi:type="ns2:receiveEDIMessagesResponse"> <head xsi:type="ns2:headResponse"> <code xsi:type="xsd:int">0</code> <message xsi:nil="true"/> </head> <body SOAP-ENC:arrayType="ns2:messageResponse[1]" xsi:type="ns2:bodyMessagesResponse"> <item xsi:type="ns2:messageResponse"> <message xsi:type="xsd:string">text</message> <from xsi:type="xsd:string">2352457999993</from> <to xsi:type="xsd:string">2352456999994</to> <id xsi:type="xsd:integer">54370</id> </item> </body> </receiveEDIMessagesReturn> </ns1:receiveEDIMessagesResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> response php 7.x: <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http_://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http_://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:interface" xmlns:xsd="http_://www.w3.org/2001/XMLSchema" xmlns:xsi="http_://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:private" xmlns:ns3="http_://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http_://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:receiveEDIMessagesResponse> <receiveEDIMessagesReturn xsi:type="ns2:receiveEDIMessagesResponse"> <head xsi:type="ns2:headResponse"> <code xsi:type="xsd:int">0</code> <message xsi:nil="true"/> </head> <body SOAP-ENC:arrayType="ns3:Map[1]" xsi:type="ns2:bodyMessagesResponse"> <item xsi:type="ns3:Map"> <item> <key xsi:type="xsd:string">message</key> <value xsi:type="xsd:string">text</value> </item> <item> <key xsi:type="xsd:string">from</key> <value xsi:type="xsd:string">2352457999993</value> </item> <item> <key xsi:type="xsd:string">to</key> <value xsi:type="xsd:string">2352456999994</value> </item> <item> <key xsi:type="xsd:string">id</key> <value xsi:type="xsd:string">54370</value> </item> </item> </body> </receiveEDIMessagesReturn> </ns1:receiveEDIMessagesResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>!!! problem only if SoapServer configured with "'cache_wsdl' => WSDL_CACHE_MEMORY" !!! if "'cache_wsdl' => WSDL_CACHE_DISK" or none the problem is not reproduced (works correct). P.S.: correct php code from prev message: class Api { public function receiveEDIMessages() { return array( 'head' => null, 'body' => array(array( 'message' => 'text', 'from' => '2352457999993', 'to' => '2352456999994', 'id' => 54370 )), ); } }