将标头身份验证信息传递给WSDL

时间:2012-12-06 13:35:46

标签: php web-services soap nusoap soap-client

我的SOAP WSDL请求如下所示,

<?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>

但我已在SOAP标头上发送HTTP身份验证参数,并从SOAP服务器捕获。

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

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

我的SOAP身份验证参数发送到服务器,但它没有显示在SOAP请求文本中。我需要在请求消息上看到它们。

我需要在WSDL文件中添加哪些类型的代码以获取Request文本,如下所示。

<?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>

1 个答案:

答案 0 :(得分:2)

$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)
));
相关问题