用php添加soap安全头

时间:2010-02-16 18:56:37

标签: c# php soap

我的任务是重写一个使用WSE代理与PHP通信的.NET应用程序。 我正在努力解决一件事。我看到了代码 UsernameToken userNameToken1 = new UsernameToken(sToken_UserName, sToken_Password, PasswordOption.SendPlainText); 我假设,它为SOAP信封添加了一个安全标头。我不知道如何在PHP中执行此操作。我尝试了以下在网上找到的以下片段

$token = new stdClass;
$token->Username = new SOAPVar($username, XSD_STRING, null, null, null, $ns);
$token->Password = new SOAPVar($password, XSD_STRING, null, null, null, $ns);

$wsec = new stdClass;
$wsec->UsernameToken = new SoapVar($token, SOAP_ENC_OBJECT, null, null, null, $ns);

$headers = new SOAPHeader($ns, 'Security', $wsec, true);
$client->__setSOAPHeaders($headers);

但我得到以下异常:

Uncaught SoapFault exception: [SOAP-ENV:Client] com.sun.xml.wss.XWSSecurityException: Receiver Requirement for nonce has not been met; nested exception is com.sun.xml.wss.XWSSecurityException: com.sun.xml.wss.XWSSecurityException: Receiver Requirement for nonce has not been met

我在这里做错了什么?是否缺少我需要知道的信息?

2 个答案:

答案 0 :(得分:2)

您是以纯文本形式发送密码(我假设通过SSL?),但Web服务还需要nonce

请参阅此讨论,因为它似乎正在处理同样的问题:http://wso2.org/forum/thread/5304

答案 1 :(得分:0)

我花了很多时间尝试使用PHP的各种WS-Security方法。

最后,我偶然发现了research paper by IBM,其中概述了一个出色的解决方案。我们现在正在使用它与我们的Web服务进行大批量集成。