gpt4 book ai didi

complexType 的 WSDL 列表 HOWTO-定义,从服务返回?

转载 作者:行者123 更新时间:2023-12-01 00:03:26 29 4
gpt4 key购买 nike

您如何在 WSDL 中定义复杂类型项的列表?

我有一个相当简单的 WSDL,有 2 种复杂类型

<xsd:complexType name="itemProperty">
<xsd:all>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="value" type="xsd:string" />
<xsd:element name="type" type="xsd:string" />
</xsd:all>
</xsd:complexType>

然后我试图像这样列出这个 complexType:

<xsd:complexType name="itemPropertyList">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:sequence>
<xsd:element name="item" type="tns:itemProperty"
maxOccurs="unbounded" minOccurs="0" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

我打算使用这个列表

<message name="getListRequest"></message>
<message name="getListResponse">
<part name="return" type="tns:itemPropertyList" />
</message>
<operation name="getList">
<documentation>Returns an array.</documentation>
<input message="tns:getListRequest" />
<output message="tns:getListResponse" />
</operation>

我得到的不是 itemProperty 类型的元素列表,而是我得到的回复,无论我尝试过什么变体(包括用显式字符串元素替换基本项目)

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getListResponse>
<return SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">name</key>
<value xsi:type="xsd:string">name_4c3b38b0b77ae</value>
</item>
<item>
<key xsi:type="xsd:string">value</key>
<value xsi:type="xsd:string">name_4c3b38b0b77ee</value>
</item>
<item>
<key xsi:type="xsd:string">type</key>
<value xsi:type="xsd:string">name_4c3b38b0b782b</value>
</item>
</item>
</return>
</ns1:getListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

有任何想法吗?这是什么 ns2:Map 东西?它已经困扰我一个多星期了!

最佳答案

解决了。

我使用 AXIS 模型来提供列表。这涉及扩展命名空间属性以包含一些额外的编码。我不知道哪个成功了,我只是在 eclipse 的 WSDL 编辑器的帮助下解决冲突的同时添加了尽可能多的内容。

<definitions 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:tns="urn:mynamespace"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="urn:mynamespace"
xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ax21="http://example.org/xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">

我还添加了 2 个额外的属性来声明模式中的限定形式属性和元素
<xsd:schema targetNamespace="urn:mynamespace" attributeFormDefault="qualified" elementFormDefault="qualified">
...
</xsd:schema>

我没有依赖 ComplexType 声明在我的模式中创建一个复杂类型的“nillable”无界序列,而是转而声明一个像这样的元素:
<xsd:element name="getListResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="tns:itemProperty" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

然后,在为我使用的操作定义消息部分时
<message name="getListResponse">
<part name="parameters" element="tns:getListResponse" />
</message>

代替
<message name="getListResponse">
<part name="return" type="tns:itemPropertyList" />
</message>

这导致返回正确的封套:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:mynamespace" 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>
<ns1:getListResponse>
<parameters xsi:type="ns1:getListResponse">
<return xsi:type="ns1:itemProperty">
<name xsi:type="xsd:string">name4c4417b644a8e</name>
<value xsi:type="xsd:string">value4c4417b644aaa</value>
<type xsi:type="xsd:string">type4c4417b644ae8</type>
</return>
<return xsi:type="ns1:itemProperty">
<name xsi:type="xsd:string">name4c4417b644b26</name>
<value xsi:type="xsd:string">value4c4417b644b64</value>
<type xsi:type="xsd:string">type4c4417b644ba1</type>
</return>
<return xsi:type="ns1:itemProperty">
<name xsi:type="xsd:string">name4c4417b644bdf</name>
<value xsi:type="xsd:string">value4c4417b644c1c</value>
<type xsi:type="xsd:string">type4c4417b644c59</type>
</return>
</parameters>
</ns1:getListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

关于complexType 的 WSDL 列表 HOWTO-定义,从服务返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3229941/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com