Jump to content

PHP SOAP Request with Authentication


JasonHarper

Recommended Posts

I'm trying to use the code below to make a SOAP request to a vendor's web service:



$client = new SoapClient('http://my.domain.com/wsdl/GuestService.WSDL', array('connection_timeout' => 15, 'trace' => 1));
$ns = 'http://vendor.domain.com/';

$headerbody = array('brand' => 'BRAND1',
'locale' => 'en_us',
'securityCredentials'=>array('applicationId'=>'ABCDEF', 'token'=>'123456789123456789123456789'));

$header = new SoapHeader($ns, 'Header', $headerbody);

$client->__setSoapHeaders($header);

$result = $client->getGuest(array('guestID' => '000787'));

However, I'm getting an error back that no credentials were supplied so I must be doing something wrong. Error message: Uncaught SoapFault exception: [soapenv:NO_CREDENTIALS]


I reached out to the vendor and they sent me an XML sample of how they're expecting to receive the data:



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prox="http://vendor.domain.com" xmlns:gues="http://vendor.domain.com/guest">
<soapenv:Header>
<prox:brand>BRAND1</prox:brand>
<prox:locale>en_us</prox:locale>
<prox:securityCredentials>
<prox:applicationId>ABCDEF</prox:applicationId>
<prox:token> 123456789123456789123456789</prox:token>
</prox:securityCredentials>
</soapenv:Header>
<soapenv:Body>
<gues:getGuest>
<guestID>000787</guestID>
</gues:getGuest>
</soapenv:Body>
</soapenv:Envelope>

I thought I had accounted for everything in the above but maybe I'm missing something obvious. Really appreciate any help!


Link to comment
Share on other sites

UPDATE: I downloaded SoapUI so I could see what's going on. It turns out the XML being generated is almost correct with one small issue....the header is inserting <item> and <key> tags within the XML:



<securityCredentials>
<item>
<key>applicationId</key>
<value>ABCDEF</key>
</item>
</securityCredentials>

What I need is:



<securityCredentials>
<applicationId>ABCDEF</applicationId>
<token>123456</token>
</securityCredentials>

If I could eliminate the tags, the XML would be correct. I've researched and can't seem to find a specific flag or setting so still stuck on what to do next.


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.