在 PHP 中使用 Microsoft .NET SOAP 服务器数据集
我阅读了 Stackoverflow 上的每个问题以及我能找到的每一篇 Google 文章。
我需要使用由使用数据集的 Microsoft 系统提供的 SOAP API。
我已经到了我觉得我需要这样做的地步:
$soapClient = new soapclient($this->wsdlUrl,array('trace'=>true));
$soapResult = $soapClient->GetScheduledSectors();
$xmlResult = $soapClient->__getLastResponse();
$xml = simplexml_load_string($xmlResult, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
而不是使用这种方法:
$result = $soapClient->GetScheduledSectors();
$xml = simplexml_load_string($result->GetScheduledSectorsResult->any)
因为 simplexml 无法解析结果,因为它缺少肥皂响应标头。
然而,即使第一个方法不会抛出任何错误,我仍然得到一个像这样的空对象:
SimpleXMLElement Object
(
[Body] => SimpleXMLElement Object
(
)
)
我真的找不到任何有关如何使用 Microsoft SOAP 服务的连贯示例。我尝试阅读 MSDN 的内容,但它专门针对他们的专有库,因此对其他人来说没什么用处。
I've read every question on Stackoverflow as well as every Google article I could find.
I need to consume a SOAP API that is being provided by a Microsoft system that uses datasets.
I've got to the point where I feel that I need to do this:
$soapClient = new soapclient($this->wsdlUrl,array('trace'=>true));
$soapResult = $soapClient->GetScheduledSectors();
$xmlResult = $soapClient->__getLastResponse();
$xml = simplexml_load_string($xmlResult, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
Rather than using this approach:
$result = $soapClient->GetScheduledSectors();
$xml = simplexml_load_string($result->GetScheduledSectorsResult->any)
Because simplexml cannot parse the result as it lacks the soap response headers.
However, even though the first method does not throw any errors I am left with an empty object like this:
SimpleXMLElement Object
(
[Body] => SimpleXMLElement Object
(
)
)
I really cannot find any coherent example of how to consume a Microsoft SOAP service. I tried reading the MSDN stuff but it's geared exclusively towards their proprietary libraries so is of little use to anybody else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试过 nusoap 后,我的头仍然撞在墙上。我最终决定手动解析 Microsoft XML。
幸运的是,有一个脚本(此处)让我省去了这样做的麻烦从头开始。
该脚本工作并将 Microsoft 数据集响应输出到我可以使用的数组中。
我对这个解决方案感觉很糟糕,因为访问数组将以硬编码的方式完成,但坦率地说,在我付出了大量努力试图找到替代解决方案之后,我认为这是一种必要的罪恶。
After trying nusoap I still hit my head against the wall. I eventually decided to manually parse the Microsoft XML.
Luckily there is a script (here) that saved me the hassle of doing this from scratch.
The script works and output the Microsoft dataset response into an array that I can use.
I feel quite bad with this solution because accessing the array is going to be done in a hard-coded way, but frankly after the amount of effort I have put into trying to find alternate solutions I see this as a necessary evil.
当遇到 SOAP 问题时,我会使用一些工具,
SoapUI 这是一个很棒的工具,可以读取WSDL 中的服务定义并为您创建存根签名。您可以测试快速访问该服务并检查响应和信息。当您自己的客户端遇到问题时,示例有效负载。
TCPMon 当事情变得艰难时,有时你必须查看数据穿过电线。通过 SoapUI 运行请求(有效),然后通过 SoapClient PHP 程序运行相同的有效负载并在传输过程中观察它们可以帮助您隔离 PHP 代码中的问题
NuSoap 当所有其他方法都失败时... NuSoap 是 SoapClient 之前的版本,但即使在 SoapClient 出现之后对于 SoapClient 无法解决的边缘情况,NuSoap 仍然很有用。还有一些功能(例如 Soap Attachements?)NuSoap 实现了 SoapClient 没有的功能。
There are a few tools I resort to when running into SOAP issues,
SoapUI It's a great tool that reads the service definition from the WSDL and creates stubbed out signatures for you. You can test hitting the service quickly and check responses & sample payloads when running into issues with your own clients.
TCPMon When the going get's tough sometimes you have to look at the data going across the wire. Running a request (that works) through SoapUI, then the same payload through a SoapClient PHP program and watching them both in transit can help you isolate issues in the PHP code.
NuSoap When all else fails... NuSoap was pre-SoapClient, but even after SoapClient hit the scenes NuSoap remains useful for edge cases where SoapClient just isn't cutting it. There are also some functions (eg. Soap Attachements?) NuSoap implements that SoapClient doesn't have.