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

nevets’s picture

Purely a guess, but I suspect it has to do with the value of $ns.

tanzeel’s picture

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

POST /TestCCService/TestCCService.asmx HTTP/1.1
Host: www.resortcom.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <AuthHeader xmlns="http://resortcom.com/testccservice">
      <Username>string</Username>
      <Password>string</Password>
    </AuthHeader>
  </soap12:Header>
  <soap12:Body>
    <AuthorizeCC xmlns="http://resortcom.com/testccservice">
      <AuthDataPub>
        <Card_Number>string</Card_Number>
        <Expiration_Date>string</Expiration_Date>
        <Transaction_Amount>double</Transaction_Amount>
        <Card_Holder>string</Card_Holder>
        <Card_Holder_Address>string</Card_Holder_Address>
        <Card_Holder_Zip>string</Card_Holder_Zip>
        <Reference_Code>string</Reference_Code>
      </AuthDataPub>
    </AuthorizeCC>
  </soap12:Body>
</soap12:Envelope>

and response from server will be

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <AuthorizeCCResponse xmlns="http://resortcom.com/testccservice">
      <AuthorizeCCResult>
        <Error_Code>int</Error_Code>
        <Auth_Code>string</Auth_Code>
        <Authorization_Date>string</Authorization_Date>
        <Authorization_Amount>double</Authorization_Amount>
      </AuthorizeCCResult>
    </AuthorizeCCResponse>
  </soap12:Body>
</soap12:Envelope>

Kindly help me with simple steps,

Thanks

Thank you,
Tanzeel

3cwebdev’s picture

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.

BDS’s picture

Hi, were you able to consume the web service?

I'm trying to do the same.

B