2016-06-29 1 views
0

PHP를 사용하여 non-wsdl SOAP 클라이언트 호출을하려고합니다. 내가 디버그는 다음과 같습니다 마지막 요청 헤더를 XML의 일부를 참조하는 경우PHP를 사용하여 non-wsdl soap 클라이언트에서 xml rquest 헤더를 설정하십시오.

try { 
$URL = 'http://example.com/webservices/security/accesscontrol.asmx'; 

$sc = new SoapClient(null, array(
    'location' => $URL, 
    'uri' => 'http://example.com/webservices/security/', 
    'trace' => 1 
)); 

$usertoken = array('UserNameToken' => 
array(
    'UserName' => 'test', 
    'Password' => 'test123' 
)); 

$header = new SoapHeader('http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $usertoken); 

$sc->__setSoapHeaders($header); 

$test = $sc->__soapCall("AuthenticateClient", 
    array(), 
    array('soapaction' => 'http://example.com/webservices/security/AuthenticateClient') 
); 

: 나는 WSDL 파일을 사용하는 경우

<SOAP-ENV:Header> 
    <ns2:Security> 
     <item><key>UserNameToken</key><value><item><key>UserName</key><value>test</value></item><item><key>Password</key><value>test123</value></item></value></item> 
    </ns2:Security> 
</SOAP-ENV:Header> 

단, XML 헤더처럼 보이는 내 코드는 다음과 같은 것입니다 이 :

가 어떻게 비 WSDL, SOAP 클라이언트 호출을 사용하여 위와 같이 헤더 부분을 만들 수

<SOAP-ENV:Header> 
    <ns2:Security> 
     <ns2:UserNameToken> 
      <ns2:UserName>test</ns2:UserName> 
      <ns2:Password>test123</ns2:Password> 
     </ns2:UserNameToken> 
    </ns2:Security> 
</SOAP-ENV:Header> 
? "사용자 이름 토큰 또는 UserName이 AuthenticateClient 비누 헤더 요청에 제공되지 않은 경우"로 인해 발생하는 오류가 발생하지 않도록하십시오.

미리 도움을 주셔서 감사합니다.

URL과 암호는 공개 할 수 없으므로 의도적으로 변경되었습니다.

답변

1

수동으로 헤더의 일부를 생성하고 SOAPHeader에 삽입 할 수 있습니다, 이런 식으로 뭔가를 시도 :

$URL = 'http://example.com/webservices/security/accesscontrol.asmx'; 

    $soapClient = new SoapClient(null, array(
     'location' => $URL, 
     'uri' => 'http://example.com/webservices/security/', 
     'trace' => 1 
    )); 

    $headerPart = ' 
      <SOAP-ENV:Header> 
       <ns2:Security> 
        <ns2:UserNameToken> 
         <ns2:UserName>DASKO</ns2:UserName> 
         <ns2:Password>welcome1</ns2:Password> 
        </ns2:UserNameToken> 
       </ns2:Security> 
      </SOAP-ENV:Header> 
    '; 

    $soapVarHeader = new SoapVar($headerPart, XSD_ANYXML, null, null, null); 

    $header = new SoapHeader(
     'http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', // Namespace - namespace of the WebService 
     'Security', 
     $soapVarHeader, 
     false // mustunderstand 
    ); 

    $soapClient->__setSoapHeaders($header); 
+0

감사 다니엘. 그것은 완벽하게 작동했습니다. –

관련 문제