note 85599 added to function.soap-soapvar-construct

From: Date: Mon, 08 Sep 2008 12:23:35 +0000
Subject: note 85599 added to function.soap-soapvar-construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-144236@lists.php.net to get a copy of this message
I spent hours trying to send an XML document (in XSD_ANYXML format) to a .NET webservice... I don't know if it's always the case with .NET webservices, but I had to use a little trick with the SoapVar object to finally get this thing working. Here is the code that works for me; Hope it will help someone! <?php // xml content $xmlDocument = '<Result> <Product id="12345" language="fr-BE"> <Data> <Brand>BrandName</Brand> <ProductName>Bag</ProductName> </Data> </Product> </Result>'; // initiate soap client ini_set("soap.wsdl_cache_enabled", "0"); $client = new SoapClient( "http://dotnetwebservice.com/Products.asmx?wsdl", array( 'trace' => 1, 'exceptions' => 1, 'soap_version' => SOAP_1_1, 'encoding' => 'ISO-8859-1', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS ) ); // prepare xml // I debugged using $client->__getLastRequest() and // then saw that the node around the XML was missing. // So the trick here is to manually add the parameter // (see the WSDL to catch the right parameter name of course). $xmlvar = new SoapVar( '<ns1:xmlDocument>'.$xmlDocument.'</ns1:xmlDocument>', XSD_ANYXML ); // send xml try { $params->xmlDocument = (object)$xmlvar; $save_result = $client->SaveProduct($params); echo "<pre>\n\n"; echo "Result :\n"; var_dump($save_result); echo "</pre>"; } catch (SoapFault $e) { echo "SOAP Fault: ".$e->getMessage()."<br />\n"; } //* DEBUG echo "<pre>\n\n"; echo "Request :\n"; echo htmlspecialchars($client->__getLastRequest())."\n"; echo "</pre>"; //*/ ?> ---- Server IP: 195.207.10.20 Probable Submitter: 80.201.194.203 ---- Manual Page -- http://www.php.net/manual/en/function.soap-soapvar-construct.php Edit -- https://master.php.net/note/edit/85599 Del: integrated -- https://master.php.net/note/delete/85599/integrated Del: useless -- https://master.php.net/note/delete/85599/useless Del: bad code -- https://master.php.net/note/delete/85599/bad+code Del: spam -- https://master.php.net/note/delete/85599/spam Del: non-english -- https://master.php.net/note/delete/85599/non-english Del: in docs -- https://master.php.net/note/delete/85599/in+docs Del: other reasons-- https://master.php.net/note/delete/85599 Reject -- https://master.php.net/note/reject/85599 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144236) next »