dongzang7182 2011-06-30 22:07
浏览 55
已采纳

“对象引用未设置为对象的实例”错误从PHP连接到SOAP服务器

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?

  • 写回答

2条回答 默认 最新

  • 普通网友 2011-06-30 23:15
    关注

    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));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题