0

i'm facing an issue with DHL Soap Web services.

I'm trying to create a test request with a basic web service (getRateRequest), but always getting an error about authentication.

I think the problem is related to Soap Basic Authentication required by the service, i've tried different ways to complete authentication, but without success.

Here's some of my test.

Test 1 - Auth in SoapClient setup

$options = array(
  'location' => $endpoint, 
  'login' => $userName,
  'password' => $password,
  'soap_version' => SOAP_1_1,
  'trace' => 1,
  'encoding' => 'utf-8',
  'stream_context' => stream_context_create(['header'=> "Content-Type:text/xml"]),
);  

$client = new SoapClient("https://wsbexpress.dhl.com:443/sndpt/expressRateBook?WSDL", $options);

And send request using __soapCall, passing the soap method and an array with all params.

Test 2 - Auth in XML request (I don't know if this is possible using Soap)

<soapenv:Header>
     <wsse:Security soapenv:mustunderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:id="UsernameToken-5" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">   
            <wsse:Username>'.$userName.'</wsse:Username>           
            <wsse:Password type="PasswordText">'.$password.'</wsse:Password>
            <wsse:Nonce encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">eUYebYfsjztETJ4Urt8AJw==</wsse:Nonce>
            <wsu:Created>' . date('Y-m-d H:i:s') . '</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   <soapenv:Header/>

And send request using CURL with an XML in post.

I think the best method is the Test 1 but always getting an error about Unauthorized user. Of course my credentials are good, because I can test the Soap service using external tools like SoapUI. I just think i'm wrong the authentication.

Thank you in advance

Francesco
  • 189
  • 1
  • 1
  • 10
  • I can't help you with your exact problem because their API is locked down (as far as I can tell), but according to their [publicly available documentation](https://developer.dhl.com/documentation/standards-guidelines), the SOAP API is a legacy one. Can you switch to a more modern one such as REST? Having lived through the SOAP era, I personally find REST so much easier to deal with. – Chris Haas May 07 '21 at 17:16

1 Answers1

1

I think you are mixing up some things. In the beginning you mention Basic Authentication but then your XML example shows a WS-Security header. Which one does the web service use?

The login and password options work only for Basic Authentication, as the SoapClient documentation says. But if your service requires Ws-Security as a SOAP header, then this won't work.

For using Ws-Security you need to extend your SoapClient to send it, as SoapClient doesn't support WS-Security out of the box. See for example:

Bogdan
  • 23,890
  • 3
  • 69
  • 61
  • Oh Yeah! that's work! Thank you so much! I've been confused because i never used Soap before, when i can choose i prefer the Rest way :) – Francesco May 08 '21 at 06:09
  • 1
    The answer was the WS-Security so i found this link helpful WS-Security for PHP SoapClient – Francesco May 08 '21 at 06:38