PHP SOAP ws 安全
我必须使用 SOAP 与在 .Net 上编写的 Web 服务进行通信。此 Web 服务需要使用证书和用户/密码进行 ws-security 身份验证。身份验证的定义如下:
<security mode="Message">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
是否有任何库为 PHP 实现了 ws-security?或者,可能在某个地方可以找到如何使用 PHP 的 SoapClient 来实现这一点的好例子?我发现的只是一个仅适用于 UserNameToken
的片段:
$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$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);
$this->soapClient = new \SoapClient('<wsdlurl>',array());
$this->soapClient->__setSoapHeaders($headers);
但服务响应
The security context token is expired or is not valid. The message was not processed.
I have to communicate with a web service written on .Net using SOAP. This web service requires ws-security authentication with certificate and user/password. Authentication is defined like this:
<security mode="Message">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
Is there any library that implements ws-security for PHP? Or, may be, somewhere can be found a good example of how to implement this using PHP's SoapClient? All I found is a snippet that works only with UserNameToken
:
$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$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);
$this->soapClient = new \SoapClient('<wsdlurl>',array());
$this->soapClient->__setSoapHeaders($headers);
But service responds with
The security context token is expired or is not valid. The message was not processed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 NuSoap
我很多年前用过它,它更比默认的 php Soap 客户端先进。尤其是跨平台通信时
Have a look at NuSoap
I used it many years ago, it was more advanced than the default php soap client. Especially when communicating cross platform