如何将数组作为值传递到 PHP Soapclient 请求中?
如何将数组作为值传递到 PHP Soapclient 请求中?
我已经实例化并连接了一个soapclient。然后,我尝试调用需要 3 个参数(字符串、字符串、哈希图)的 Web 服务方法。
这是我期望在下面工作的内容。但是当查看 xml 输出时,params 节点为空。
soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 'params' => array('email' => '[email protected]', 'password' => 'password', 'blah' => 'blah')));
肥皂体 xml 最终如下所示(注意空的 params 元素):
<SOAP-ENV:Body><ns1:doSomething>
<id>blah</id>
<page>blah</page>
<params/>
</ns1:register></SOAP-ENV:Body>
How can I pass in an array as a value into a PHP soapclient request?
I have a soapclient instantiated and connected already. I then try to make a call to a webservice method that expects 3 parameters (string, string, hashmap).
Here is what I expected to work below. But when viewing the xml output, the params node is empty.
soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 'params' => array('email' => '[email protected]', 'password' => 'password', 'blah' => 'blah')));
The soap body xml ends up like this (note the empty params element):
<SOAP-ENV:Body><ns1:doSomething>
<id>blah</id>
<page>blah</page>
<params/>
</ns1:register></SOAP-ENV:Body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 JAX-WS Web 服务,可能是 hashmap 输入参数存在问题。生成的 xsd 架构对于哈希图似乎不正确。将映射放置在包装器对象中会导致 JAX-WS 输出正确的 xsd。
然后php代码就成功了。我发现我不需要 SoapVar 或 SoapParam,并且如果没有 MapWrapper,这些方法都无法工作。
这是使用包装器生成的正确 xsd
这是 JAX-WS 仅使用 hashmap 生成的不正确模式
最后一点。包装 HashMap使用此解决方案,但 HashMap没有。该对象被映射到 xsd:anyType,它作为 xsd 模式对象而不仅仅是对象进入 java webservice。
For JAX-WS webservices it may be a problem with the hashmap input parameter. The xsd schema generated seems to be incorrect for hashmaps. Placing the map in a wrapper object causes JAX-WS to output the correct xsd.
Then the php code will succeed. I found I didn't need SoapVar or SoapParam and could not get either of those methods to work without the MapWrapper.
Here is the correct xsd generated with the wrapper
Here is the incorrect schema generated by JAX-WS with just the hashmap
One last note. Wrapping HashMap<String, String> worked with this solution, but HashMap<String, Object> did not. The Object gets mapped to xsd:anyType which comes into the java webservice as a xsd schema object rather than just Object.
根据 Web 服务定义,hashmap 参数可能需要具有无法直接从数组创建的特定结构/编码。您可能需要检查 WSDL,并查看 SoapVar< /a> 和 SoapParam 类以获取有关 Soap 参数构造的更多选项。
Depending on the webservice definition, the hashmap parameter might need to have a specific structure/encoding that can not be directly created from an array. You might want to check the WSDL on that, and take a look into the SoapVar and the SoapParam classes for more options on Soap parameter construction.