【发布时间】:2011-05-14 02:07:04
【问题描述】:
我正在使用 SoapServer 类在 PHP 中构建 Web 服务,但遇到了复杂类型转换的问题。
WSDL 是完全有效的,PHP SoapClient 可以完美地处理它,但似乎存在返回的复杂类型未正确转换的问题。当在 .Net 中使用服务时,这一点就暴露出来了,因为我收到了异常,表明该类型不存在于给定的命名空间中。
我多次破坏我的函数,更改元素上的命名空间,但 .Net 继续给我错误,无论我使用什么命名空间。
考虑以下脚本的缩写:
function getCommands() {
$output = array();
// ...
foreach($result as $row) {
$output[] = new SoapVar($row, SOAP_ENC_OBJECT, 'ns1:command');
}
return $output;
}
简短的回应:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:MyWebService"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getCommandsResponse>
<return SOAP-ENC:arrayType="ns1:command[12]" xsi:type="ns1:ArrayOfCommand">
<item xsi:type="ns1:command">
<!-- ... -->
</item>
<!-- ... -->
</return>
</ns1:getCommandsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我注意到xmlns:ns1 是通过 WSDL 定义的,它确实与 WSDL 中的命名空间相匹配。但是,.Net SOAP 客户端似乎不明白command 元素是在那里定义的。但是,它确实知道这是定义 ArrayOfCommand 的地方。
所以我的问题是多方面的:
- 这是 SoapServer 的已知错误吗?
- 如果不是,我是否在 WSDL 中遗漏了一些严重的东西?
- 我的对象编码是否正确?
- 这是 .Net 的问题吗?如果是这样,解决方法是什么?
【问题讨论】:
标签: php soap xsd wsdl soapserver