1

我已经使用 ladon web 服务 ( http://ladonize.org ) 编写了一个 python web 服务,我想使用 Java 和 Axis2 访问 SOAP 接口。

我已经使用 python 和 SUDS 客户端库成功地测试了 WS。

调用远程服务方法直到返回类型被转换。ladon 生成的 WSDL 包含以下类型定义:

<xsd:complexType name="Sensor">
    <xsd:sequence>
        <xsd:element maxOccurs="1" minOccurs="1" name="description" type="xsd:string"/>
        <xsd:element maxOccurs="1" minOccurs="1" name="host" type="xsd:string"/> 
        <xsd:element maxOccurs="1" minOccurs="1" name="sensorId" type="xsd:long"/>
        <xsd:element maxOccurs="1" minOccurs="1" name="service" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

发送的 SOAP 请求(用 捕获tcpmon)是

<?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <ns1:create xmlns:ns1="urn:SensorService">
                <hostId>testHost</hostId>
                <serviceId>testService/serviceId>
                <description>testDescription</description>
            </ns1:create>
    </soapenv:Body>
</soapenv:Envelope>

相应的回应:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:ns="urn:SensorService" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <ns:createResponse>
            <result>
                <sensorId>16</sensorId>
                <host>testHost</host>
                <description>testDescription</description>
                <service>testService</service>
            </result>
        </ns:createResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

基本上,问题在于结果类型中元素的顺序。说明xsd需要

  1. description
  2. host
  3. sensorId
  4. service

但响应与此序列不匹配,因此导致 Axis2 ADBException : Unexpected subelement sensorId。它工作得很好,当我

  1. 手动下载 WSDL 文件并
  2. 更改返回类型的类型定义以匹配响应中实际返回的序列,并且
  3. 从修改后的文件中重新生成服务存根(使用 Maven 插件)。

服务存根是使用 maven 插件自动生成的,随后作为依赖项包含在项目中。

我想避免这个手动步骤。是否可以在服务器端修改导出顺序?

类型定义似乎按字典顺序列出了元素,但响应是另一个不同的顺序。

首先出现的是 WSDL 响应类型遵循在原始 python 返回类型定义中定义属性的顺序。我已经改变了这个顺序,但它没有效果(我在安装更新的包之前停止了服务器)。

提前谢谢了,

bvfnbk

4

0 回答 0