为什么在文档/文字样式中使用WSDL的SoapClient返回带有额外键元素的数组?

mar*_*out 5 php soap wsdl

我们正在将RPC /编码的web服务转换为document/literal/wrapped.WSDL(使用nusoap)已经被重写以使用新格式.

我像这样使用PHP SoapClient:

new SoapClient($wsdlUrl, array(
    'cache_wsdl' => WSDL_CACHE_NONE,
    'trace' => true,
    'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
));
Run Code Online (Sandbox Code Playgroud)

相关的WSDL部分如下所示(应该遵循WS-I Basic Profile):

<xsd:complexType name="messages">
    <xsd:sequence>
        <xsd:element name="item" type="xsd:string" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="some_functionResponseType">
    <xsd:all>
        <xsd:element name="return" type="tns:messages" form="unqualified"/>
    </xsd:all>
</xsd:complexType>

<message name="some_functionResponse">
    <part name="parameters" element="tns:some_functionResponseType"/>
</message>

<operation name="some_function">
    <input message="tns:some_functionRequest"/>
    <output message="tns:some_functionResponse"/>
</operation>
Run Code Online (Sandbox Code Playgroud)

当我提交请求时,XML响应是这样的:

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <some_functionResponse xmlns="urn:toets_nl_wsdl">
      <messages xmlns="">
        <item>foo</item>
        <item>bar</item>
      </messages>
    </some_functionResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

当我在PHP中转储结果对象时,它看起来像这样:

stdClass Object
(
    [messages] => stdClass Object
        (
            [item] => Array             // <-- here
                (
                    [0] => foo
                    [1] => bar
                )

        )

)
Run Code Online (Sandbox Code Playgroud)

为什么结果树中有一个额外的元素"item"?当我们仍在使用RPC/encoded时,这不存在.

有没有办法在处理响应时删除该元素?

Sve*_*ven 4

您的 WSDL 明确指出存在一个出现次数不受限制的项目,其中包含字符串(也称为数组)。因此,PHP 只是向您呈现 WSDL 中描述的结构以及服务器返回的结构。

我看不出有什么问题。不要仅仅因为 Soap 的功能相同就期望它与 RPC 相同。如果您不希望该项目元素存在,请更改 WSDL 和服务 - 但这可能比使 PHP 客户端代码适应新的数据结构更困难。

您甚至使用了 SOAP_SINGLE_ELEMENT_ARRAYS,这对于避免检查元素是否确实是数组来说是一件好事。