【发布时间】:2015-04-20 17:15:13
【问题描述】:
我正在尝试使用 WS-Security 连接到 Web 服务,但我收到一条错误消息“不正确的安全标头”,这里是 SoapHeader:
<soapenv:Header>
<wsse:Security mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken Id="ABC-123">
<wsse:Username>*****</wsse:Username>
<wsse:Password>*****</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
这里是连接的 PHP 代码:
<?php
$client = new SoapClient("https://www.weservice.com/service?wsdl");
//Body of the Soap Header.
$headerbody = array("UsernameToken" => array("Username" => "******",
"Password" => "******"));
//Create Soap Header.
$header = new SoapHeader("wsse", "Security", $headerbody);
//set the Headers of Soap Client.
$client->__setSoapHeaders($header);
try{
$result = $client->__soapCall("sendBill", array("fileName" => "filename",
"contentFile" => "byteArray"));
}catch(SoapFault $e){
echo $e;
}
提前致谢。
【问题讨论】:
-
你能提供 wsdl 吗?然后我们可以验证您提供的 XML 是否匹配。如果 wsdl 很大,只需 Policy 部分即可。
-
谢谢 muttonUp,不过,我可以使用 NuSoap 库解决这个问题。但这给我带来了一个新问题:在调用部分“contentFile”中我应该发送一个“byte[]”,我有它但就像它没有被识别......你能帮我吗?
标签: php soap ws-security