【问题标题】:PHP SoapServer and Complex TypesPHP SoapServer 和复杂类型
【发布时间】: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 的地方。

所以我的问题是多方面的:

  1. 这是 SoapServer 的已知错误吗?
  2. 如果不是,我是否在 WSDL 中遗漏了一些严重的东西?
  3. 我的对象编码是否正确?
  4. 这是 .Net 的问题吗?如果是这样,解决方法是什么?

【问题讨论】:

    标签: php soap xsd wsdl soapserver


    【解决方案1】:

    我能够通过再次处理我的 WSDL 的 &lt;types/&gt; 部分来解决此问题,并使用 the Google WSDL 作为参考。然后,我必须在我的 PHP 函数中使用一些魔法,将 $command 的元素转换为 WSDL 中它们各自的类型,并将整个命令编码为 ns2:command。当与 WSDL 保持一致时,这一切都很好地结合在一起,.Net 使用它的难度为零。

    我很惊讶开发社区中没有人愿意回答这个问题,但我希望有人能够从中至少找到一些关于如何解决他们自己的这个问题实例的方向。

    【讨论】:

      猜你喜欢
      • 2012-12-09
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多