Zend_Soap_Client 调用 ASP.net Web 服务时出错:“...未设置为对象的实例”

发布于 2024-10-02 16:46:10 字数 1059 浏览 1 评论 0原文

我正在尝试使用 Zend_Soap_Client 与 ASP.net Web 服务进行通信。这是我的客户电话:

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

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

但是这总是给我错误:

System.NullReferenceException:未将对象引用设置为对象的实例。在 Service.UserDetails(UserDetail UserDetail)

一些谷歌搜索显示这是一个相当常见的问题。最常见的解决方案似乎是将参数作为数组传递,所以我尝试了:

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

但这给出了相同的错误。我还尝试将参数作为 stdClass 对象传递,将数组嵌套在另一个以 'params' 作为键的数组中,以及其他一些东西,但错误总是相同的。

我有Web服务本身的ASP代码,相关方法是:

public Result UserDetails(UserDetail UserDetail) {

    [some stuff]

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

错误是由GenerateData()调用引起的。

我假设 UserDetails 方法获取 null 而不是我的对象作为参数,但我不确定应该如何调用该方法,或者如何进一步调试它。我发现的大多数 Zend_Soap_Client 示例似乎都在使用 WSDL,但该服务并非如此;不确定这是否相关。任何帮助表示赞赏!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡绿茶香 2024-10-09 16:46:10

我最终解决了这个问题:

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

$client->UserDetails($userDetails);

似乎 ASP.net 期望(并返回)参数嵌套在与被调用方法同名的对象/数组中。

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.

眼角的笑意。 2024-10-09 16:46:10

如果您有可能更改 asp.net 代码,我建议您尝试不带参数的 UserDetails 方法的实现,以确保代码不会损坏。

然后,我将在 asp.net 中创建一个消费者方法,调试 http 请求并查看 userdetail-object 如何以数组形式序列化/分解。那么“只是”从 php 创建类似的 http 请求即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文