2014-02-28 72 views
2

在我的WSDL文件我有一個用戶認證模塊:致命錯誤:未捕獲的SOAPFault異常:[NS1:Client.AUTH_1]驗證失敗

<!-- User authentication --> 

    <element name="UserAuthentication"> 
     <complexType> 
      <sequence> 
       <element name="iId" type="xsd:int" /> 
       <element name="sPassword" type="xsd:string" /> 
       <element name="sType" type="api:UserType" /> 
      </sequence> 
     </complexType> 
    </element> 

我試圖實例化一個SOAP調用像這樣:

$client = new SoapClient("http://api.example.com/v2/example?wsdl", 
    array(
     'iId' => 123456, 
     'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi', 
     'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds')); 

提供了實際值。劇本報告:

SoapFault exception: [ns1:Client.AUTH_1] Authentication Failed in 

我錯過了什麼?

+0

任何變化affiliatewindow API是這樣的:

所以像這樣的東西試試? API的消息是什麼?只是另一個瘋狂的猜測:缺少標題? – Max

+0

@Gal - 是的,最深刻的 – cookie

+0

@Max,的確如此。我沒有得到這份工作;)。 – cookie

回答

2

您正將選項中的請求數據傳遞給SoapClient,而不是作爲soap調用的參數。

的代碼應該是這樣的(假設SOAP調用Authenticate):

$client = new SoapClient("http://api.example.com/v2/example?wsdl"); 

$response = $client->Authenticate(Array(
    'iId' => 123456, 
    'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi', 
    'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds')); 
    )); 

而且,在任何情況下,你應該使用try..catch防止異常崩潰的代碼。

try 
{ 
    // code here 
} 
catch(Exception $e) 
{ 
    // error handling goes here 
    die("Error: ". $e->getMessage()."\n"); 
} 
+0

Max和poncha的一些好評,謝謝。誰應該得到賞金? – cookie

+0

我可能也可能沒有通過這一點:http://stackoverflow.com/questions/22173191/fatal-error-uncaught-soapfault-exception-client-soap-error-encoding-object – cookie

1

如果沒有完整的WSDL規範,很難分辨問題出在哪裏。但我的猜測是你在看規格。錯誤。可能這些是需要發送的標頭,而不是需要調用的實際方法。

// SOAP client options 
$options = array(
    'soap_version' => SOAP_1_2, 
    'trace'  => true, 
); 

// initialise the SOAP client 
$apiURL = 'http://api.example.com/v2/example?wsdl'; 
$namespace = 'http://api.example.com/v2/example?wsdl'; 

$client = new SoapClient($apiURL, $options); 

// the SOAP headers 
$headers = array(); 

$ua = array(
    'iId' => 123456, 
    'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi', 
    'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds', 
); 

$headers[] = new SoapHeader($namespace, 'UserAuthentication', $ua); 

// we could add multiple headers if needed 

$client->__setSoapHeaders($headers); 

// call the API function 
$response = $client->__soapCall("whateverYourTryingToCall", null); 
相關問題