15

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

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?

wonder95
  • 3,825
  • 8
  • 45
  • 74
  • 3
    As of 2017/06/09, the WSDL is not available and the question is incomplete... – Alfabravo Jun 09 '17 at 19:21
  • "Object reference not set to an instance of an object." typically means a parameter is wrong/missing in the SOAP-request. Be sure to check not only the but also the (this was the problem in my case). – marcovtwout Feb 24 '20 at 09:36

3 Answers3

27

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));
Jonathan
  • 5,953
  • 1
  • 26
  • 35
  • Hmm, I tried that before, but I must have done something wrong. Anyway, that gets me closer, but now I get this error: Catchable fatal error: Object of class stdClass could not be converted to string in /Users/steve/Sites/mysite/hawley_client.php on line 15 Line 15 is this line, BTW. Looking at the headers, the info is being sent properly now. – wonder95 Jul 01 '11 at 00:09
  • Major facepalm here: I was using print() with an object. Changed to var_dump, and it works. Thanks. – wonder95 Jul 01 '11 at 00:32
3

Probably it's not the same case but it also gives the same error if you don't specify empty strings in fields you don't need to use, taken from http://www.sitepoint.com/forums/showthread.php?755549-SOAP-XML-Object-reference-not-set-to-an-instance-of-an-object

darkstar_mx
  • 456
  • 5
  • 8
0

I my case the problem was in typo:

In given docs the filed name was documentShipmentAddress (and I was using this)

but in wdsl (schema) was:

shipmentAddress

So that could be the problem with this error message. I have changed the field name to shipmentAddress and it solved the problem.

Marek G.
  • 99
  • 9