Axis1非常非常简单的服务,Axis2客户端引发了意外的子元素异常

时间:2011-09-19 23:08:37

标签: namespaces axis2 wsdl2java

我正在将我的webesrvice客户端从Axis迁移到Axis2-1.6.1,但服务本身不会被更改。我遇到了WDSL2Java生成的代码问题,因为我收到了“意外的子元素”异常。 WDSL非常简单,因为只有一个服务,它只接收一个String并返回一个Date:

<wsdl:definitions targetNamespace="xml.generator.ws">
    <!--WSDL created by Apache Axis version: 1.4
    Built on Apr 22, 2006 (06:55:48 PDT)-->
    <wsdl:message name="generateToday1Request">
        <wsdl:part name="idCompany" type="xsd:string"/>
    </wsdl:message>
    <wsdl:message name="generateToday1Response">
        <wsdl:part name="generateToday1Return" type="xsd:dateTime"/>
    </wsdl:message>
    <wsdl:portType name="WSGenerator">
        <wsdl:operation name="generateToday1" parameterOrder="idCompany">
            <wsdl:input message="impl:generateToday1Request" name="generateToday1Request"/>
            <wsdl:output message="impl:generateToday1Response" name="generateToday1Response"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="ValuationsXMLGeneratorSoapBinding" type="impl:WSGenerator">
        <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="generateToday1">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="generateToday1Request">
                <wsdlsoap:body namespace="http://generacion.stmts.bpi.com" use="literal"/>
            </wsdl:input>
            <wsdl:output name="generateToday1Response">
                <wsdlsoap:body namespace="xml.generator.ws" use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="WSGeneratorService">
        <wsdl:port binding="impl:ValuationsXMLGeneratorSoapBinding" name="ValuationsXMLGenerator">
            <wsdlsoap:address location="http://naboo:8080/Statements2/services/ValuationsXMLGenerator"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

我使用以下选项生成了源代码:

<axis-wsdl2java
    output="${src.java}"
    testcase="false"
    wsdlfilename="http://naboo:8080/Statements2/services/ValuationsXMLGenerator?wsdl"
    serverside="false"
    unpackclasses="true"
    unwrap="true"
    suppressprefixes="true"
    namespacetopackages="xml.generator.ws=com.spb.eco.valuations.xml"
    generateAllClasses="true"/>

我使用生成的代码来调用服务,并发送以下正文:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
 <soapenv:Body>
  <generateToday1 xmlns="http://generacion.stmts.bpi.com">
   <idCompany xmlns="">US0010001</idCompany>
  </generateToday1>
 </soapenv:Body>
</soapenv:Envelope>

我收到以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <generateToday1Response xmlns="http://generacion.stmts.bpi.com">
   <generateToday1Return>2011-09-19T22:56:53.781Z</generateToday1Return>
  </generateToday1Response>
 </soapenv:Body>
</soapenv:Envelope>

这是服务器的server-config.wsdd:

<?xml version="1.0" ?>
<deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
    <service name="ValuationsXMLGenerator" provider="java:RPC" style="rpc" use="literal">


        <!-- Nombre de la clase que implementa los metodos expuestos -->
        <parameter name="className" value="com.bpi.stmts.generacion.WSGenerator"/>

        <parameter name="allowedMethods" value="generateToday1"/>
        <parameter name="wsdlTargetNamespace" value="xml.generator.ws"/>
    </service>

    <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
    <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>

    <transport name="http">
        <requestFlow>
            <handler type="URLMapper"/>
            <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
        </requestFlow>
        <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>
        <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>
        <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
        <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
        <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
        <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>
    </transport>
    <transport name="local">
        <responseFlow>
            <handler type="LocalResponder"/>
        </responseFlow>
    </transport>

</deployment>

这可能不是更简单,但生成的代码失败,出现以下异常:

引起:org.apache.axis2.databinding.ADBException:意外的子元素 {http://generacion.stmts.bpi.com} generateToday1Return

在这种情况下,元素的顺序或类似的顺序没有问题,所以我不明白客户端失败的原因。有什么想法吗?

TIA

JL

2 个答案:

答案 0 :(得分:0)

根据WS-I基本配置文件,您不应该有generateToday1Return元素的命名空间。但是响应它有一个命名空间。因此,您的响应与wSDL文件不匹配。 有关详细信息,请查看此处[1]。

[1] http://wso2.org/library/2935

答案 1 :(得分:0)

问题在于SOAP绑定样式,在您的WSDL中,您使用“RPC”作为样式,Axis2不支持RPC。我遇到了同样的问题,我使用Axis1客户端测试了Web服务,但是在Axis2中也是如此。

Later I have changed the SOAP binding style to DOCUMENT and then I have regenerated the client stubs with Axis2. After that I was able to invoke the Web Services successfully and got the proper response as well. 

 So, Change the SOAP binding style to DOCUMENT.