“对象引用未设置为对象的实例"从PHP连接到SOAP服务器时出错 [英] "Object reference not set to an instance of an object" error connecting to SOAP server from PHP

查看:302
本文介绍了“对象引用未设置为对象的实例"从PHP连接到SOAP服务器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从PHP连接到SOAP服务器,但我不了解如何登录并获取所需的数据.我要连接的服务是Hawley USA服务 http://hawleyusa.com/thcServices/StoreServices.asmx).我一直在看几篇有关如何连接的文章,并且了解了一些基础知识.我已经验证自己在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>\n";
  print($client->InventoryList(array("LoginID" => $login_id, "Password" => $password)));
  echo "\n";
}
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

调试时,我可以看到$ client实例已启动,所以我不确定为什么会收到此错误.

When debugging, I can see the $client instance initiated, so I'm not sure why I'm getting this error.

第二个问题:我是否正确传递了用户ID和密码?

Second question: Am I passing the user ID and password correctly?

谢谢.

更新:我输入了$ client-> __ getLastRequest,这就是我得到的:

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>

所以我可以看到我缺少我的登录ID和密码.如何将它们添加到我的InventoryList调用中?

So I can see that I'm missing my login ID and password. How do I add them to my InventoryList call?

推荐答案

您已经关闭.查看WSDL,InventoryList方法采用一个称为请求"的对象.稍微修改您的通话线路:

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));

这篇关于“对象引用未设置为对象的实例"从PHP连接到SOAP服务器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆