我正在使用 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的问题吗?如果是这样,解决方法是什么?