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
https://forums.phpfreaks.com/topic/288093-php-soap-request-with-authentication/
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.


Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.