2012-03-04 8 views
1

저는 PHP의 SOAP 라이브러리를 처음 사용하고 있으며, 내가 치고있는 서비스를위한 유효한 SoapHeader를 만드는 데 문제가 있습니다. 다음은 서비스 WSDL이다 : 나는 그것을 실행하면namespace 항목의 배열을 가진 PHP SoapHeader

<? 
try { 
    $options = array(
     'exceptions'=>true, 
     'trace'=>1, 
    ); 

    $ns = 'http://www.scene7.com/IpsApi/xsd'; 
    $client = new SoapClient('http://s7sps1api.scene7.com/scene7/webservice/IpsApi-2010-01-31.wsdl', $options); 
    $auth = (object)array(
     'user'=>'***', 
     'password'=>'***' 
     ); 

    $header = new SoapHeader($ns, 'authHeader', $auth, false); 
    $client->__setSoapHeaders(array($header)); 
    $client->getCompanyInfo(array('companyName' => '***')); 
    print "<pre>\n"; 
    print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n"; 
    print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n"; 
    print "</pre>"; 
} 
catch(SoapFault $ex) 
{ 
    print "<pre>\n"; 
    print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n"; 
    print "</pre>"; 
    var_dump($ex->faultcode, $ex->faultstring, $ex->faultactor, $ex->detail, $ex->_name, $ex->headerfault); 
} 

?> 

내가 얻을 다음 :

http://s7sps1api.scene7.com/scene7/webservice/IpsApi-2010-01-31.wsdl

가 여기 내 PHP 스크립트의

내가 그것을 필요로하는 곳에 거의이다
Request : 
<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.scene7.com/IpsApi/xsd/2010-01-31" xmlns:ns2="http://www.scene7.com/IpsApi/xsd"><SOAP-ENV:Header><ns2:authHeader><user>***</user><password>***</password></ns2:authHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getCompanyInfoParam><ns1:companyName>***</ns1:companyName></ns1:getCompanyInfoParam></SOAP-ENV:Body></SOAP-ENV:Envelope> 

string(14) "soapenv:Server" string(11) "ipsApiFault" NULL object(stdClass)#12 (1) { ["ipsApiFault"]=> object(stdClass)#13 (2) { ["code"]=> string(5) "30002" ["reason"]=> string(81) "Missing 'user' element for header '{http://www.scene7.com/IpsApi/xsd}authHeader'." } } NULL NULL 

, 그러나 사용자와 패스워드 노드는 내가 생각한 것처럼 scene7 네임 스페이스를 가지고 있지 않습니다.

나는이에 대한 인증의 VAR를 변경하는 경우 :

$auth = (object)array(
    'ns2:user' => '[email protected]', 
    'ns2:password' => 'lkjasdf1' 
    ); 

그것은 작동하지만 내가 하드 코딩 NS2이야 것으로 해키 보인다. 이 작업을 수행하는 올바른 방법은 무엇입니까?

감사합니다.

답변