PHP SOAP ws-security

3

我需要与一个使用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.
1个回答

0

看一下NuSoap

我多年前用过它,它比默认的php soap客户端更先进。特别是在跨平台通信方面。


很遗憾,NuSoap不支持WS-Security。 - Timur
哦,抱歉,我以为它可以 :( - Billy2mates
类似于 https://code.google.com/p/wse-php/source/browse/soap-wsse.php 的东西就可以解决问题了。它支持 X509 密钥等。 - Timur
感谢您提供更好的答案 :) - Billy2mates

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接