phpzend-frameworksoapzend-soap

Zend_Soap_Client error calling ASP.net web service: '...not set to an instance of an object'


I'm trying to use Zend_Soap_Client to communicate with an ASP.net web service. Here's my client call:

$client = new Zend_Soap_Client(null, array(
    'location' => 'http://example.com/service.asmx',
    'uri' => 'http://example.com/'
));

$user = new UserDetail();
$result = $client->UserDetails($user);

However this always gives me the error:

System.NullReferenceException: Object reference not set to an instance of an object. at Service.UserDetails(UserDetail UserDetail)

some googling revealed that this is quite a common problem. The most common solution seemed to be to pass the parameters as an array, so I tried:

$result = $client->UserDetails(array('UserDetail' => $user));

but this gave the same error. I also tried passing the params as a stdClass object, nesting the array in another with 'params' as the key, and a few other things but the error is always the same.

I have the ASP code for the web service itself, the relevant method is:

public Result UserDetails(UserDetail UserDetail) {

    [some stuff]

    Hashtable ht = new Hashtable();
    ht = UserDetail.GenerateData();
}

the error is caused by the GenerateData() call.

I assume the UserDetails method is getting null instead of my object as the parameter, but I'm not sure how I should be calling the method, or how I can debug this further. The majority of the Zend_Soap_Client examples I've found seem to be using WSDL, which this service is not; not sure if that is relevant. Any help appreciated!


Solution

  • I eventually solved this with:

    $userDetails = new UserDetails();
    $userDetails->UserDetail = $user;
    
    $client->UserDetails($userDetails);
    

    it seems ASP.net expects (and returns) params to be nested in an object/array with the same name as the method being called.