【问题标题】:How to fine control how a SOAP response type is converted into a PHP type?如何精细控制 SOAP 响应类型如何转换为 PHP 类型?
【发布时间】:2013-08-03 22:06:32
【问题描述】:

我正在使用 PHP SOAP 扩展 (SoapClient) 来调用远程操作。它的 WSDL 类型如下:

<s:element name="OperationResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="OperationResult">
                <s:complexType mixed="true">
                    <s:sequence>
                        <s:any/>
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:sequence>
    </s:complexType>
</s:element>

据我所知,类型是“任何东西”。调用结果转化为嵌套的stdClass对象,不好处理:

object(stdClass)[3]
  public 'OperationResult' => 
    object(stdClass)[4]
      public 'any' => string 'xml string here...'

(这实际上是由 SOAP 扩展本身执行的)

我如何控制这个对象的创建方式?我尝试将 classmap 选项传递给 SOAP 客户端,但它不起作用:我得到了实例,但属性是 null

手动解析结果的问题一目了然。我可以使用来自$result-&gt;OperationResult-&gt;any 的字符串创建一个新的SimpleXmlElement,但如果WSDL 发生更改,它将无法工作。

【问题讨论】:

    标签: php xml soap php-5.3 soap-client


    【解决方案1】:

    您可以通过该类映射功能在 PHP 中将结果转换为几乎任何内容,但问题是您是否应该这样做,因为相同的 Soap 数据结构通常用于请求和响应。重复使用它们!

    我的一般方法是使用类映射功能将所有这些 ComplexType 结构映射到 PHP 类。如果该结构不适合预期用途,我有一个映射器步骤,可以在 PHP 中转换结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 2011-08-12
      相关资源
      最近更新 更多