2013-10-29 37 views
3

我正在爲客戶端開發api。我收到以下信息:在非WSDL模式下使用PHP SOAP客戶端

​​

我需要在非WSDL模式下配置相同的PHP SOAP客戶端。我寫了以下,但它似乎並沒有工作:

$wsdl = null; 
$options = array(
    'uri'  => 'http://xyz-crm.example/WebAPI/Custom/project_name/XML/', 
    'location' => 'http://xyz-crm.exmaple.com/WebAPI/Custom/project_name/XML/', 
    'login' => 'foobar', 
    'password' => 'spameggs' 
); 
$client = new SoapCLient($wsdl, $options); 

我只是想先做一個成功的ping到api。看看事情是否正常。我在這裏做錯了什麼?

更新1

我做了以下修改:

$wsdl = null; 
$options = array(
    'uri'   => "http://xyz-crm.example/WebAPI/Custom/project_name/XML/", 
    'location'  => "http://xyz-crm.example/", 
    'Username'  => "foobar", 
    'Password'  => "spameggs", 
    'soap_version' => '1.2' 
); 
$client = new SoapClient($wsdl, $options); 
$client = $client->getListings(); 

我得到的錯誤:looks like we got no XML document

[Edit by me, hakre: This update was done as feedback to answer #1 . It changes the location option using a shortened URL (reason not given by OP) and it adds the soap_version option (as suggested in answer #1, but not as constant but as string (containing an invalid value), so there should be no wonder this creates an error, a correct option value is given in answer #1 (the SOAP_1_1 constant) and by intention, the correct value would be the SOAP_1_2 constant for this example). Error message as commented by OP was "SOAP Fault: Wrong version."]

更新2

我嘗試以下,但它仍然失敗:

$listing = $client->getListings(); 
$request = $client->__getLastRequest(); 

停止執行在第一線本身而沒有去第二個。

[Edit by me, hakre: As review has shown wrong configuration options in Update 1 already which are not addressed in Update 2 it would be a miracle if it still wouldn't fail. The execution stops because an Exception is thrown and no error/exception handling is done]

+0

您是否收到任何錯誤消息(是否打開了錯誤報告?)? – DanFromGermany

+1

SOAP錯誤:版本錯誤。這是我得到的錯誤。我也對api uri感到困惑。在網上我看到.asmx作爲URI或位置的格式的例子。這是我第一次使用SOAP。 –

回答

2

模具URI或文件的結局並不重要,它甚至可以是.jpg,沒有默認。

看一看similiar問題:Does this SOAP Fault mean what I think it means?

如果你把錯誤信息進入正題,藏漢作爲你的請求的XML輸出這將是有益的。

試試你的SoapClient實例的陣列中設置SOAP版本的常量之一(嘗試不同的):

new SoapClient($url, array("soap_version" => SOAP_1_1,....... 

SOAP_1_2 ...

要調試XML嘗試答案從Inspect XML created by PHP SoapClient call before/without sending the request

您更新後的問題的錯誤消息看起來不像是來自PHP,看起來更像是來自webservice的答案,意味着您的請求實際上正在工作。

+0

嘿丹, 我對這個問題做了更新。看一看。 –