Although this isn't directly Drupal related, I am building it into a Drupal module, so I hope to get some help from the Drupal community.
I am trying to send a very simply SOAP request through PHP 5's SOAP client and every response comes back with:
Server was unable to process request. ---> Object reference not set to an instance of an object.
The request doesn't have any elements in the body, and uses two elements in the header for authentication. Using SOAPui and the service WSDL I am able to sucessfully test the call that I am trying to make. Here is the valid XML request that it sends:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cmic="http://www.cmicdataservices.com/">
<soap:Header>
<cmic:Authentication>
<!--Optional:-->
<cmic:UserName>USERNAME</cmic:UserName>
<!--Optional:-->
<cmic:Password>PASSWORD</cmic:Password>
</cmic:Authentication>
</soap:Header>
<soap:Body>
<cmic:CheckIfAuthorized/>
</soap:Body>
</soap:Envelope>
I have tried for two solid days to form a valid request in PHP and am always coming up with the above error. I have tried many methods of forming the request -- here is the latest:
$client = new SoapClient($server,array("trace" => 1,"exceptions" => 0));
$auth = array();
$auth['UserName'] = new SOAPVar($id, XSD_STRING, null, null, null, $ns);
$auth['Password'] = new SOAPVar($pw, XSD_STRING, null, null, null, $ns);
$headerBody = new SOAPVar($auth, SOAP_ENC_OBJECT);
$header = new SOAPHeader($ns, 'Authentication', $headerBody);
$client->__setSOAPHeaders(array($header));
$client->CheckIfAuthorized();
Here is this request when I print print it from Drupal:
?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.cmicdataservices.com/" xmlns:ns2="cmic">
<SOAP-ENV:Header><ns2:Authentication><ns2:UserName>USERNAME</ns2:UserName><ns2:Password>PASSWORD</ns2:Password></ns2:Authentication></SOAP-ENV:Header><SOAP-ENV:Body><ns1:CheckIfAuthorized/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Any ideas?
Comments
Purely a guess, but I
Purely a guess, but I suspect it has to do with the value of $ns.
Calling external web service from drupal
Same problem here,
I want to make a call to external webservice by drupal but dont know the process to call webservice, kindly help me
xml request which will be send is
and response from server will be
Kindly help me with simple steps,
Thanks
Thank you,
Tanzeel
You can use my above example
You can use my above example to help get your started. It will need to be modified for your particular SOAP server.
Searching for, and reading up on the PHP SoapClient command should help you too.
Latest status
Hi, were you able to consume the web service?
I'm trying to do the same.
B