PHP SoapClient: How to prefix SOAP parameter tag name with namespace? -


i'm using php's soapclient consume soap service receiving error soap service cannot see parameters.

<tns:genericsearchresponse xmlns:tns="http://.../1.0">   <tns:status>     <tns:statuscode>1</tns:statuscode>     <tns:statusmessage>invalid calling system</tns:statusmessage>   </tns:status> </tns:genericsearchresponse> 

the xml php's soapclient sends soap call:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"      xmlns:ns1="http://.../1.0">   <soap-env:body>     <ns1:genericsearchrequest>       <uniqueidentifier>12345678</uniqueidentifier>       <callingsystem>web</callingsystem>     </ns1:genericsearchrequest>   </soap-env:body> </soap-env:envelope> 

i used soap-ui initially, works when consuming same wsdl. xml soap-ui sends call:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:ns1="http://.../1.0">   <soap-env:body>     <ns1:genericsearchrequest>       <ns1:uniqueidentifier>12345678</ns1:uniqueidentifier>       <ns1:callingsystem>web</ns1:callingsystem>     </ns1:genericsearchrequest>   </soap-env:body> </soap-env:envelope> 

the difference being uniqueidentifier , callingsystem parameters prefixed ns1 in soap-ui request.

i've tried using passing soapvar objects soapclient call not augment parameter tags , prefix them ns1.

i know web valid callingsystem value xsd specifies it, , works when using soap-ui.

my current soapclient code:

try {   $client = new soapclient($wsdl, array('trace' => 1));   $query = new stdclass;   $query->uniqueidentifier = $id;   $query->callingsystem = 'web';   $response = $client->genericuniqueidentifiersearch($query); } catch (soapfault $ex) {   $this->view->error = $ex->getmessage();   ... } 

i found this blog post hoping there might cleaner implementation.

update: used solution question pretty clunky:

$xml = "<ns1:genericsearchrequest>"      . "<ns1:uniqueidentifier>$id</ns1:uniqueidentifier>"      . "<ns1:callingsystem>web</ns1:callingsystem>"      . "</ns1:genericsearchrequest>"; $query = new soapvar($xml, xsd_anyxml);  $response = $this->client->__soapcall(     'genericuniqueidentifiersearch',     array($query) ); 

the reasonable way found this, use combination of soapvar , soapparam.

note, soapvar has options specify namespace of each var.

so code should like:

$wrapper = new stdclass; $wrapper->uniqueidentifier = new soapvar($id, xsd_string, "string", "http://www.w3.org/2001/xmlschema", "uniqueidentifier", "ns1"); $wrapper->callingsystem = new soapvar("web", xsd_string, "string", "http://www.w3.org/2001/xmlschema", "callingsystem", "ns1"); $searchrequest = new soapparam($wrapper, "genericsearchrequest");  try{     $response = $this->client->genericuniqueidentifiersearch($searchrequest); }catch(exception $e){     die("error calling method: ".$e->getmessage()); } 

if issue attributes , method getting different namespaces, try specifying namespace soapvar url defined in envelope (in example: "http://.../1.0") like:

$wrapper->uniqueidentifier = new soapvar($id, xsd_string, "string", "http://www.w3.org/2001/xmlschema", "uniqueidentifier", "http://.../1.0"); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -