【问题标题】:Magento API V2 - WSDL and associative multi arraysMagento API V2 - WSDL 和关联多数组
【发布时间】:2013-03-03 11:20:51
【问题描述】:

我扩展了 Magento V2 API,因此创建了一个 wsdl.xml。我的网络服务返回一个关联多数组。我google了一下,发现了两个复杂类型的定义:

<complexType name="associativeMultiArray">
    <all>
        <element name="associativeArray" type="typens:associativeArray" minOccurs="0" />
    </all>
</complexType>
<complexType name="stringArray">
    <all>
        <element name="multi_data" type="typens:associativeMultiArray" minOccurs="0" />
    </all>
</complexType>

<message name="methodResponse">
    <part name="result" type="typens:stringArray" />
</message>

另一个:

<complexType name="associativeMultiArray">
    <complexContent>
        <restriction base="soapenc:Array">
            <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:associativeMultiEntity[]"/>
        </restriction>
    </complexContent>
</complexType>

<complexType name="associativeMultiEntity">
    <all>
        <element name="key" type="xsd:string"/>
        <element name="value" type="typens:ArrayOfString"/>
    </all>
</complexType>

<complexType name="ArrayOfString">
    <complexContent>
        <restriction base="soapenc:Array">
            <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
        </restriction>
    </complexContent>
</complexType>

<message name="methodResponse">
    <part name="result" type="typens:associativeMultiArray" />
</message>

问题是,这两个都不起作用。如果我在查询后输出结果:

Array
(
    [0] => stdClass Object
    (
    )
)

无论我返回array('test) 还是array('key'=&gt;'value'),它始终是相同的输出。基本上我有两个问题:

  • ArrayOfStringassociativeArrayassociativeMultiArray 是否声明以下内容:<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento"> <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
  • 如果我有非常复杂的数组结构,比如 10 维关联数组,是否必须在 wsdl.xml 中声明每个维?我该如何处理?它是如何工作的?为什么上述声明不起作用?

【问题讨论】:

  • 我也有同样的问题

标签: arrays web-services api magento wsdl


【解决方案1】:

这不是问题的精确解决方案,但我找到了另一种解决方法:只需使用 json_encode 将数组序列化为 JSON 并使用 json_decode 对其进行解码。有了这个,数组可以是任何复杂的。则返回类型为 wsdl 中的 xsd:string

【讨论】:

  • 仅供参考:xsd:array 将与关联数组一起使用,(并且可能与多数组一起使用,我不确定。)但是,我们在使用它时遇到了 WSDL 验证。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-15
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多