PHP SOAP ws 安全

发布于 2025-01-04 02:53:25 字数 1150 浏览 2 评论 0原文

我必须使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻梦旅人 2025-01-11 02:53:25

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文