SOAP WSDL 关联数组 [英] SOAP WSDL Associative Arrays

查看:29
本文介绍了SOAP WSDL 关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SOAP wsdl 文件中定义关联数组?到目前为止,我是这样定义数组元素类型的:

How can I define an associative array in a SOAP wsdl file? This is how I define an array element type so far:

<wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="webservice.wsdl" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
        <xsd:complexType name="ArrayOfString">
            <xsd:complexContent>
                <xsd:restriction base="soapenc:Array">
                    <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="tns:arrayElement"/>
                </xsd:restriction>
            </xsd:complexContent>
        </xsd:complexType>
    </xsd:schema>
</wsdl:types>

谢谢!

我说的是 PHP 关联数组,并且我想使用任意数量的任何键=> 值字符串对,它们将被转换回通信方另一侧的关联数组.作为替代方案,我可以将序列化数组或 json 表示作为字符串发送,但我也想知道如何在 wsdl 中执行此操作.

I'm talking about PHP associative arrays, and I want to use any number of any key=>value string pairs, that will be converted back to associative arrays on the other side of the communication party. As an alternative, I could send the serialized array, or json representation as string, but I'd like to know how to do this in wsdl also.

谢谢!

推荐答案

要在soap上传输php关联数组,您需要在wsdl中定义以下内容:

to transfer a php associative array over soap you will need to define following in your wsdl:

<xsd:complexType name="KeyValueData">
      <xsd:sequence>
        <xsd:element minOccurs="1" maxOccurs="1" name="id" type="string"/>
        <xsd:element minOccurs="1" maxOccurs="1" name="name" type="string"/>
        <xsd:element minOccurs="1" maxOccurs="1" name="data" type="string"/>
      </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ArrayOfKeyValueData">
    <xsd:sequence>
      <xsd:element minOccurs="0" maxOccurs="unbounded"
               name="keyval" type="tns:KeyValueData"/>
    </xsd:sequence>
</xsd:complexType> 

现在将新定义的 ArrayOfKeyValueData 类型指定为结果类型或参数

now specify your new defined ArrayOfKeyValueData type as the type of your result or as parameter

<message name='getPostStatsResponse'>
  <part name='Result' type='ArrayOfKeyValueData'/>
</message>

并用类似的东西指定您的操作

and specify your operation with someting like

<operation name='getPostStats'>
    <input message='tns:getPostStatsRequest'/>
    <output message='tns:getPostStatsResponse'/>
</operation>

这将适用于某种用 php 编写的返回类似内容的 Web 服务

this will work fine with some kind of web service written in php that returns something like

return array("k1" => "v1", "k2" => "v2");

如果您使用 php 作为客户端,您将在客户端获得完全相同的数组.其他语言或肥皂库可能会产生其他结构,因为并非每种语言都有这种关联数组"概念.

if you are using php as client, you will get exactly the same array on the client side. other languges or soap libraries may produce other structure, as not every language has this kind of "associative array" concept.

这篇关于SOAP WSDL 关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆