2016-04-20 116 views
1

我想用soapui訪問soap接口。一切正常:PHP SOAP空響應

請求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soc="www.example.com"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <soc:getMailboxes> 
     <userId>512</userId> 
     </soc:getMailboxes> 
    </soapenv:Body> 
</soapenv:Envelope> 

響應:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <getMailboxesResponse xmlns="http://www.example.com"> 
     <getMailboxesReturn> 
      <mailboxes> 
       <mailboxes> 
        <administratorNumbers/> 
        <administratorUsers> 
        <administratorUsers>512</administratorUsers> 
        </administratorUsers> 
        <allowsSuppressedNumbers>true</allowsSuppressedNumbers> 
        <deactivatedByAdmin>false</deactivatedByAdmin> 
        <deactivatedByUser>false</deactivatedByUser> 
        <mailNotificationActive>true</mailNotificationActive> 
        <name>speech box</name> 
        <notificationNumber xsi:nil="true"/> 
        <number>123123123</number> 
        <pin xsi:nil="true"/> 
        <recordConferenceCallActive>false</recordConferenceCallActive> 
        <sendSmsCount>0</sendSmsCount> 
        <sendSmsLimit>0</sendSmsLimit> 
        <smsNotificationActive>false</smsNotificationActive> 
        <tag xsi:nil="true"/> 
        <type>CLASSIC</type> 
        <voicemailEnabled>false</voicemailEnabled> 
        <whitelistedNumbers/> 
       </mailboxes> 
      </mailboxes> 
      <responseCode> 
       <ID>0</ID> 
       <name>OK</name> 
      </responseCode> 
     </getMailboxesReturn> 
     </getMailboxesResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

我想這個代碼,即可獲得相同的結果:

$client = new SoapClient($soapURL,array('login'   => "...", 
              'password'  => "...", 
              'trace'     => 1, 
              'features' => SOAP_SINGLE_ELEMENT_ARRAYS)); 

      $response = $client->getMailboxes(512); 
      echo var_dump(get_object_vars($response)); 

和我這個結果:

array(2) { 
    ["mailboxes"]=> 
    object(stdClass)#4 (0) { 
    } 
    ["responseCode"]=> 
    object(stdClass)#5 (2) { 
    ["ID"]=> 
    int(0) 
    ["name"]=> 
    string(2) "OK" 
    } 
} 

我假設有一些值,如在soapui響應中的響應(如object(stdClass)#5)?如果我發送錯誤的用戶標識,我會得到正確的錯誤信息。誰能幫我?

更新1: 的getMailboxes方法創建此代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com"> 
    <SOAP-ENV:Body> 
     <ns1:getMailboxes> 
      <userId>512</userId> 
     </ns1:getMailboxes> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

更新2:

,如果我用這個代碼:

$response = $client->getMailboxes(["userId"=>512]); 

我得到這個肥皂碼。用戶ID應該是512,而不是1

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="www.example.com"> 
<SOAP-ENV:Body> 
    <ns1:getMailboxes> 
     <userId>1</userId> 
    </ns1:getMailboxes> 
</SOAP-ENV:Body></SOAP-ENV:Envelope> 

我用肥皂代碼:

echo "REQUEST:\n" . $client->__getLastRequest() 
+0

您可以提供'getMailboxes'方法內容嗎? – walkingRed

+0

你是什麼意思?我使用SoapClient類。 getMailboxes派生自wsdl(至少我認爲是這樣)。 – user3488359

回答

0

此調用不正確:在原始XML

$response = $client->getMailboxes(512); 

注意,你是告訴它什麼512意味着什麼?您也可以通過使用關聯數組來標識您發送的參數:

$response = $client->getMailboxes(["userId"=>"512"]); 
+0

感謝您的回覆。我嘗試了你的代碼,但是我得到了一個錯誤的結果: $ response = $ client-> getMailboxes([「userId」=> 512]);創建一個值爲1的userId。 <?xml version =「1.0」encoding =「UTF-8」?> \t \t \t \t (我收到$ client - > __ getLastRequest()的soap代碼) – user3488359

+0

嘗試將ID作爲字符串傳遞,請參閱我的上次編輯。 – miken32

+0

結果沒有變化 – user3488359