Header in SOAPclient PHP

143 views Asked by At

I have very little experience with SOAP. How do I specify username and password in a soap client ? See below the corresponding section of the WSDL.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xx="xx.services.soap">
<soapenv:Header>
  <cb:UserName>_SNIP_</cb:UserName>
  <cb:Password>_SNIP_</cb:Password>
</soapenv:Header>
<soapenv:Body>
  <cb:checkOrderable>
     <arg2>
        <EAN>9789084999820</EAN>
        <DeliveryChannel>CBW</DeliveryChannel>
     </arg2>
  </cb:checkOrderable>
</soapenv:Body>
</soapenv:Envelope>

I have the following code but the server response that username and password are not given:

$client = new SoapClient("https://xxxxx...xxxxxService?wsdl");

$params = array(
  "UserName" => "abc",
  "Password" => "def",
  "EAN" => $ean,
  "DeliveryChannel" => "xxx",
);

$response = $client->checkOrderable( $params );
print_r( $response );
1

There are 1 answers

0
javabrett On

You should use login and password parameters for BASIC auth. Also worth adding 'trace' => true. If your WSDL is password-protected then you will need to pass these to the SoapClient constructor.