Adi*_*Adi 7 php soap wsdl web-services
如何在SOAP wsdl文件中定义关联数组?这就是我到目前为止定义数组元素类型的方法:
<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>
Run Code Online (Sandbox Code Playgroud)
谢谢!
我在谈论PHP关联数组,我想使用任意数量的任何key =>值字符串对,它们将被转换回通信方另一端的关联数组.作为替代方案,我可以将序列化数组或json表示作为字符串发送,但我想知道如何在wsdl中执行此操作.
谢谢!
要通过soap传输php关联数组,您需要在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>
Run Code Online (Sandbox Code Playgroud)
现在将新定义的ArrayOfKeyValueData类型指定为结果类型或参数
<message name='getPostStatsResponse'>
<part name='Result' type='ArrayOfKeyValueData'/>
</message>
Run Code Online (Sandbox Code Playgroud)
并指定你喜欢的操作
<operation name='getPostStats'>
<input message='tns:getPostStatsRequest'/>
<output message='tns:getPostStatsResponse'/>
</operation>
Run Code Online (Sandbox Code Playgroud)
这将适用于某些用PHP编写的Web服务返回类似的东西
return array("k1" => "v1", "k2" => "v2");
Run Code Online (Sandbox Code Playgroud)
如果你使用php作为客户端,你将在客户端获得完全相同的数组.其他语言或肥皂库可能会产生其他结构,因为并非每种语言都有这种"联想阵列"概念.
如果您想使用字符串数组,您只需在需要该数组的类型中声明即可:
<xs:complexType name="SomeTypeThatUsesAnArrayOfStrings">
<xs:sequence>
<xs:element name="TheStringValue" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
顺便问一下,“关联数组”是什么意思?像 c++ 地图或 python 字典之类的东西?
归档时间: |
|
查看次数: |
13771 次 |
最近记录: |