2012-01-06 95 views
0

我剛剛開始使用php進行soap通信。似乎無法從我的SoapClient獲得響應

我訪問返回一個true或false取決於三個屬性的「用戶名」,「密碼」和「域」

這裏是我的匿名請求代碼web服務:

//VARS 
$username = 'example'; 
$password = 'example'; 
$domain = 'example'; 

$client = new SoapClient("https://www.example.com/example.wsdl"); 

try { 
    $client->authenticate(array($email, $password, $domain)); 
    echo $client->__getLastResponse(); 
} catch (SoapFault $e) { 
    echo $e->getMessage(); 
} 

die(); 

現在,正如我所提到的,我是新手,所以我不確定我寫的內容是否正確,請幫忙!

這裏是WSDL的相關部分(再次,匿名):

//MESSAGE 
<message name="AuthenticateRequest"> 
    <part type="xsd:string" name="username"/> 
    <part type="xsd:string" name="password"/> 
    <part type="xsd:string" name="domain"/> 
</message> 
<message name="AuthenticateResponse"> 
    <part type="xsd:boolean" name="authenticationResponse"/> 
</message> 

//OPERATION 
<portType name="LDAPPortType"> 
    <operation name="authenticate"> 
     <documentation> 
      Connects to the LDAP server with the parameters provided. If successful, this function then attempts to bind to the LDAP directory with the user's credentials. The function returns TRUE on success or FALSE on failure. 
     </documentation> 
     <input message="tns:AuthenticateRequest"/> 
     <output message="tns:AuthenticateResponse"/> 
    </operation> 
</portType> 

我錯過了什麼重要的?
感謝您的幫助,非常感謝!

回答

3

我想你會需要$username,而不是$email在此行

$client->authenticate(array($email, $password, $domain)); 
          ^

還試着用數組來指定參數名稱爲:

$client->authenticate(array("username"=>$username, 
       "password"=>$password, "domain"=>$domain)); 
+0

啊,感謝察覺我的錯誤!不幸的是,我仍然無法獲得回報。我使用了上面例子中詳細描述的參數名稱。我沒有收到錯誤,或任何異常都沒有迴應到頁面。 – 2012-01-06 10:11:31

+0

@DanielHanly:嘗試查看由'echo「創建的請求REQUEST:」。 $ proxy - > __ getLastRequest()。 「」;'在你通過認證之後。您需要查看頁面源以查看此內容。還保存你的返回到一個變量和打印,作爲'$結果= $客戶端 - >認證(數組(「用戶名」=> $用戶名, 「密碼」=> $密碼,「域」=> $域)); print_r($ result);'你也應該捕獲異常,而不是SoapFault來查看其他異常,如'catch(Exception $ e){echo $ e-> getMessage(); }' – 2012-01-06 10:14:42

+0

沒有運氣,我很害怕。 wsdl是https,這會影響結果嗎? $ proxy變量來自哪裏?我試着'echo「REQUEST:」。 $ client - > __ getLastRequest()。 「」;「但沒有迴應,我收到了REQUEST這個詞......但再次感謝您的幫助。 – 2012-01-06 10:33:32