【问题标题】:Soap WS-Security error: Incorrect security headerSoap WS-Security 错误:安全标头不正确
【发布时间】: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


【解决方案1】:

我终于以不同的方式解决了这个事件。 使用 Php,无法发送字节数组中的 zip 文件,因为一些罕见的原因(可能是 Php 对基于 soap 协议的附件的支持不佳)。

所以我将语言更改为 C#,现在我可以测试一个虚拟文件到 soap 服务,我遇到了一些(已解决的)问题,但我收到了来自服务的成功响应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 2020-09-24
    • 2011-04-26
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多