Search code examples
phpweb-servicessoapnusoapsoap-client

Pass Header Authentication Information to WSDL


My SOAP WSDL Request is shown like follows,

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body><unit>3452</unit>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

But I have send HTTP Authentication Parameters on SOAP header and Captured from SOAP server.

$client = new SoapClient("call.wsdl",array(
"trace"      => 1,
"exceptions" => 0,
"login" => 'xxxxx',
"password" => 'xxxx'));

$result = $client->getCALL($unit);

My SOAP Authentication parameters are send to server but it doesn't shown on SOAP request text. I need to seen them on Request message.

Which types of code should I need to add on WSDL file to get Request text as follows.

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header>
    <Login>BonZ</Login>
    <Password>xxxx</Password>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <unit>3452</unit>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Solution

  • $CREDENTIALS = 'Login:Password';
            $auth = base64_encode($CREDENTIALS);
            $context = array('http' =>
                array(
                    'header'  => "Authorization: Basic ".$auth
                )
            );
    
    $trac["stream_context"]=stream_context_create($context);
    $client = new SoapClient("call.wsdl",array(
    "trace"      => 1,
    "exceptions" => 0,
    "login" => 'xxxxx',
    "password" => 'xxxx'
    "stream_context"=>stream_context_create($context)
    ));