2012-02-09 53 views
3

我必須與使用SOAP在.Net上編寫的Web服務進行通信。此Web服務需要帶證書和用戶/密碼的ws安全認證。身份驗證是這樣定義的:PHP SOAP ws-security

<security mode="Message"> 
    <transport clientCredentialType="None" /> 
    <message clientCredentialType="UserName" /> 
</security> 

是否有任何實現ws-security for PHP的庫?或者,可能在某處可以找到一個如何使用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. 

回答

0

看一看NuSoap

我很多年前用它的服務響應,這是更先進比默認的php肥皂客戶端。特別是在跨平臺溝通時

+0

不幸的是,NuSoap不支持WS-Security – Timur 2013-05-14 09:42:18

+0

哦,對不起,我認爲它確實: – Billy2mates 2013-05-14 17:56:52

+0

像https://code.google.com/p/wse-php/source/browse /soap-wsse.php就可以了,它支持X509按鍵等。 – Timur 2013-05-14 19:22:34