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

StackOverflow https://stackoverflow.com/questions/4184470

سؤال

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!

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

If you have any possibility to change the asp.net code I'd suggest you try an implementation of the method UserDetails without parameters just to make sure that code isn't broken.

I would then create a consumer-method in asp.net, debug the http-request and see how the userdetail-object is serialized/broken down in array form. Then it's "just" a matter of creating a similar http request from php.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top