2016-07-18 39 views
0

プロジェクト用にSOAP Webサービスを使用する必要があります。SOAPヘッダを構築する

WebServiceが、このようなSOAPヘッダを介して認証を必要とする:従って

<soap:Header> 
    <wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <wsse:UsernameToken> 
      <wsse:Username>STAGING_WS</wsse:Username> 
      <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">ANDREANI</wsse:Password> 
     </wsse:UsernameToken> 
    </wsse:Security> 
</soap:Header> 

、iは以下のようにのSOAPHeaderクラスを使用してヘッダを構築しようとした:

$ns = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; 

$auth = new \StdClass(); 
$auth->Username = new \SoapVar('STAGING_WS', XSD_STRING, NULL, $ns, NULL, $ns); 
$auth->Password = new \SoapVar('ANDREANI', XSD_STRING, NULL, $ns, NULL, $ns); 

$token = new \StdClass(); 
$token->UsernameToken = new \SoapVar($auth, SOAP_ENC_OBJECT, NULL, $ns, 'UsernameToken', $ns); 
$security = new \SoapVar(new \SoapVar($token, SOAP_ENC_OBJECT, NULL, $ns, 'UsernameToken', $ns), SOAP_ENC_OBJECT, NULL, $ns, 'Security', $ns); 

$header = new \SoapHeader('wsse', 'Security', $security, true); 

をしかしをgeneratdヘッダは等しくありません:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.andreani.com.ar" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns3="wsse"> 
<env:Header> 
<ns3:Security env:mustUnderstand="true"> 
<ns2:UsernameToken> 
<ns2:Username>STAGING_WS</ns2:Username> 
<ns2:Password>ANDREANI</ns2:Password> 
</ns2:UsernameToken> 
</ns3:Security> 
</env:Header> 
<env:Body> 
<ns1:ConfirmarCompra/> 
</env:Body> 
</env:Envelope> 

これはSecurityタグの名前空間がUsernameTokenUsernamePasswordタグと同じものになります

$header = new \SoapHeader($ns, 'Security', $security, true); 

答えて

0

はに最後の行を変更してみてください。セキュリティ名前空間のローカル名はまだns2であり、wsseではありませんが、それは本当に重要ではありません。正しいSOAPサーバーは、名前空間URLが正しい限り、それを受け入れる必要があります。

+0

返信ありがとうございますが、結果は同じです。 – ramiromd

関連する問題