PHP SoapClient 复杂参数如何?
我正在使用 PHP SoapClient 来使用 Web 服务。
当服务参数很简单并且类似于 $client->GetProductById(array('productId' => 'ID')); 时,一切工作正常。确实有用...
但是我需要访问的服务之一需要更复杂的参数..我已经使用 SoapUI 来测试 Web 服务,并且使用 SoapUI 我可以轻松地使其工作..
问题是我无法使其与 PHP SoapClient 一起使用,我根本找不到一种方法来表示所有这些参数。
发送到服务器的 Soap 消息是这样的(从 SoapUI 复制)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:slps="http://www.microsoft.com/slps/">
<soapenv:Header/>
<soapenv:Body>
<slps:GetLicensesByFilter>
<slps:filter>
<slps:ExcludeCommercial>false</slps:ExcludeCommercial>
<slps:ExcludeTrial>false</slps:ExcludeTrial>
<slps:IssueDateRange>
<slps:End>2011-12-31T00:00:00.000Z</slps:End><slps:Start>2011-11-01T00:00:00.000Z</slps:Start>
</slps:IssueDateRange>
<slps:ProductId>1275b704-7622-c2xx-922e-76186497f744</slps:ProductId>
<slps:SkuId>A35138F43-0119-0719-802a-B48CCE6229A4</slps:SkuId>
</slps:filter>
<slps:retrievalOptions>LicenseInfo</slps:retrievalOptions><slps:pageIndex>0</slps:pageIndex>
</slps:GetLicensesByFilter>
</soapenv:Body>
</soapenv:Envelope>
I'm using PHP SoapClient to consume a webservice..
Everything is working fine when service parameters are simple and something like $client->GetProductById(array('productId' => 'ID')); does the trick...
but one of the services that I need to access to, requires more complex parameters.. I've used SoapUI to test the webservice, and with SoapUI I can easily make it work..
The problem is that I can't make it work with PHP SoapClient, I simply can't find a way to represent all those parameters..
The Soap message that is sent to the server is this (copied from SoapUI)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:slps="http://www.microsoft.com/slps/">
<soapenv:Header/>
<soapenv:Body>
<slps:GetLicensesByFilter>
<slps:filter>
<slps:ExcludeCommercial>false</slps:ExcludeCommercial>
<slps:ExcludeTrial>false</slps:ExcludeTrial>
<slps:IssueDateRange>
<slps:End>2011-12-31T00:00:00.000Z</slps:End><slps:Start>2011-11-01T00:00:00.000Z</slps:Start>
</slps:IssueDateRange>
<slps:ProductId>1275b704-7622-c2xx-922e-76186497f744</slps:ProductId>
<slps:SkuId>A35138F43-0119-0719-802a-B48CCE6229A4</slps:SkuId>
</slps:filter>
<slps:retrievalOptions>LicenseInfo</slps:retrievalOptions><slps:pageIndex>0</slps:pageIndex>
</slps:GetLicensesByFilter>
</soapenv:Body>
</soapenv:Envelope>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这里的方法是根据您的 *.wsdl 文件生成相关的 php 类。这可以使用 wsdl2php 等工具来完成 --> http://www.urdalen.no/wsdl2php/。
之后,您可以使用生成的 Service 类来执行 Web 服务调用,或者您可以只获取相关类并在创建 Soap 客户端实例时使用“classmap”选项。
I think the way to go here is to generate the relevant php classes according to your *.wsdl file. This can be done using tools like wsdl2php --> http://www.urdalen.no/wsdl2php/.
After that, you can use the generated Service class to do your webservice calls or you can just get the relevant classes and use the "classmap" option when creating an instance of your Soap Client.
编辑:终于我明白了;)
可能不是最好的方法,但它有效,我遵循了用户留下的提示在 PHP 论坛中..基本上我必须创建一些类来表示参数结构,然后当我必须使用 SoapClient 的“classmap”选项将该 WSDL 类型映射到我的 PHP 类中时...
edit: Finally I got it ;)
Probably not the best approach but it works, I've followed a tip that a user left in PHP forums..basicaly I had to create some classes to represent the parameters structure, and then when I had to use the 'classmap' option of SoapClient to map that WSDL type into my PHP classes...