問題描述
我第一次嘗試從 PHP 連接到 SOAP 服務(wù)器,但我不明白如何登錄并獲取我需要的數(shù)據(jù).我嘗試連接的服務(wù)是 Hawley USA 服務(wù) http://hawleyusa.com/thcServices/StoreServices.asmx).我一直在看一些關(guān)于如何連接的帖子,我了解了一些基礎(chǔ)知識(shí).我已經(jīng)確認(rèn)我在我的 PHP 中啟用了 SOAP,我只是想獲取一個(gè)庫(kù)存列表.這是我正在使用的代碼:
";print($client->InventoryList(array("LoginID" => $login_id, "Password" => $password)));回聲
";}捕獲(SoapFault $exception){回聲 $exception;}
但是,當(dāng)我運(yùn)行此代碼時(shí),出現(xiàn)此錯(cuò)誤:
SoapFault 異常:[soap:Server] 服務(wù)器無(wú)法處理請(qǐng)求.--->你調(diào)用的對(duì)象是空的.在/Users/steve/Sites/mysite/hawley_client.php:12
在調(diào)試時(shí),我可以看到 $client 實(shí)例已啟動(dòng),所以我不確定為什么會(huì)出現(xiàn)此錯(cuò)誤.
第二個(gè)問題:我是否正確傳遞了用戶名和密碼?
謝謝.
更新:我輸入了 $client->__getLastRequest,這就是我得到的:
所以我可以看到我丟失了我的登錄 ID 和密碼.如何將它們添加到我的 InventoryList 調(diào)用中?
離你很近了.查看 WSDL,InventoryList 方法采用一個(gè)名為請(qǐng)求"的對(duì)象.稍微修改您的電話線路:
$client->InventoryList(array("request" => array("LoginId" => $login_id, "Password" => $password));
I'm making my first attempt to connect to a SOAP server from PHP, and I'm not understanding how to log in and get the data I need. The service I'm trying to connect to is the Hawley USA service http://hawleyusa.com/thcServices/StoreServices.asmx). I've been looking at a few posts on how to connect, and I get the basics. I've verified that I have SOAP enabled in my PHP, and I'm just trying to get an inventory list. Here's the code I'm using:
<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://hawleyusa.com/thcServices/StoreServices.asmx?WSDL";
$login_id = 'mylogin_id';
$password = 'mypassword';
$client = new SoapClient($wsdl_path);
try {
echo "<pre>
";
print($client->InventoryList(array("LoginID" => $login_id, "Password" => $password)));
echo "
";
}
catch (SoapFault $exception) {
echo $exception;
}
However, when I run this code, I get this error:
SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /Users/steve/Sites/mysite/hawley_client.php:12
When debugging, I can see the $client instance initiated, so I'm not sure why I'm getting this error.
Second question: Am I passing the user ID and password correctly?
Thanks.
Update: I threw in $client->__getLastRequest, and this is what I got:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hawleyusa.com/thcServices/">
<SOAP-ENV:Body>
<ns1:InventoryList/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So I can see that I'm missing my login ID and password. How do I add them to my InventoryList call?
You're close. Looking at the WSDL the InventoryList method takes an object called "request". Modify your call line slightly:
$client->InventoryList(array("request" => array("LoginId" => $login_id, "Password" => $password));
這篇關(guān)于“未將對(duì)象引用設(shè)置為對(duì)象的實(shí)例"從 PHP 連接到 SOAP 服務(wù)器時(shí)出錯(cuò)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!