SoapClient:如何传递多个同名元素?
我有以下代码:
$telnums = array(10, 20, 30);
$obj = new StdClass();
$obj->telnums = new StdClass();
foreach ($telnums as $telnum) {
$obj->telnums = $telnum;
}
call_user_func(array($this->client, 'createDomain'), new SoapVar($obj, SOAP_ENC_OBJECT));
$this->client 是 SoapClient 类的一个实例。
它会生成以下请求:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="...">
<SOAP-ENV:Body>
<ns1:createDomain>
<createDomainRequest>
<telnums>30</telnums>
</createDomainRequest>
</ns1:createDomain>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但我需要
<createDomainRequest>
<telnums>10</telnums>
<telnums>20</telnums>
<telnums>30</telnums>
</createDomainRequest>
如何实现这一目标?
PS:PHP 5.2.6-3ubuntu4.5 与 Suhosin-Patch 0.9.6.2 (cli)(构建时间:2010 年 1 月 6 日 22:25:33)
提前致谢!
I have following code:
$telnums = array(10, 20, 30);
$obj = new StdClass();
$obj->telnums = new StdClass();
foreach ($telnums as $telnum) {
$obj->telnums = $telnum;
}
call_user_func(array($this->client, 'createDomain'), new SoapVar($obj, SOAP_ENC_OBJECT));
There $this->client is an instance of SoapClient class.
And it generates following request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="...">
<SOAP-ENV:Body>
<ns1:createDomain>
<createDomainRequest>
<telnums>30</telnums>
</createDomainRequest>
</ns1:createDomain>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But I need
<createDomainRequest>
<telnums>10</telnums>
<telnums>20</telnums>
<telnums>30</telnums>
</createDomainRequest>
How I can achieve this?
P.S.: PHP 5.2.6-3ubuntu4.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan 6 2010 22:25:33)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我最近遇到了类似的情况,我发现这种模式通常可以解决问题。
其工作原理是因为它紧密模拟 WSDL 规定的相同数据结构
I had landed into a similar scenario recently and I found this pattern usually does the trick.
The reason this works is because it closely emulates the same data structure as prescribed by your WSDL
正确答案应该是:
:)
The correct answer should have been:
:)
找到可行的解决方案是一件痛苦的事,但最终并不那么难。使用 SoapParam 甚至令人惊讶地简单和整洁:
It is a pain in the buttock to find a working solution, but eventually it's not that hard. Even surprisingly easy and neat by using SoapParam's:
这是我使用的代码格式:
Here is the code format that I used:
通过扩展 SoapClient 并覆盖 __doRequest() 方法来修复它,我按照此处所述修改请求: http://www.php.net/manual/en/soapclient.dorequest.php#57995
对我来说看起来很糟糕,但它“就在这里,现在”工作。
Fixed it by extends SoapClient and overrides __doRequest() method where I modify request as descibed here: http://www.php.net/manual/en/soapclient.dorequest.php#57995
Looks terrible for me, but it works "right here, right now".