场景:使用CXF客户端(由wsdl2java生成)来访问axis1生成的webservice。每当webservice返回值的对象里有数组的时候,就出错:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri:"", local:"name"). Expected elements are <{http://localhost:8080/AxisTest/services/GetArray}name>,<{http://localhost:8080/AxisTest/services/GetArray}strArray> 
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)
at $Proxy23.getArrayBean(Unknown Source)
at cxf.client.helloarray.HelloWorldArray_GetArray_Client.main(HelloWorldArray_GetArray_Client.java:46)

但是该webservice用axis自己生成的客户端访问是没有问题的,并且axis发布的其他webservice(不包含数组格式的数据)用CXF访问也是没有问题。从表面上猜想可能是因为命名空间的问题,但是从wsdl来看似乎又没有问题wsdl如下:
<wsdl:definitions targetNamespace="http://localhost:8080/AxisTest/services/GetArray">

<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->

<wsdl:types>

<schema elementFormDefault="qualified" targetNamespace="http://localhost:8080/AxisTest/services/GetArray">

<complexType name="ArrayOf_xsd_string">

<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="xsd:string"/>
</sequence>
</complexType>

<complexType name="ArrayBean">

<sequence>
<element name="name" nillable="true" type="xsd:string"/>
<element name="strArray" nillable="true" type="impl:ArrayOf_xsd_string"/>
</sequence>
</complexType>
<element name="getArrayBeanReturn" type="impl:ArrayBean"/>
</schema>
</wsdl:types>

<wsdl:message name="getArrayBeanResponse">
<wsdl:part element="impl:getArrayBeanReturn" name="getArrayBeanReturn"/>
</wsdl:message>
<wsdl:message name="getArrayBeanRequest">   </wsdl:message>

<wsdl:portType name="HelloWorldArray">

<wsdl:operation name="getArrayBean">
<wsdl:input message="impl:getArrayBeanRequest" name="getArrayBeanRequest"/>
<wsdl:output message="impl:getArrayBeanResponse" name="getArrayBeanResponse"/>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="GetArraySoapBinding" type="impl:HelloWorldArray">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="getArrayBean">
<wsdlsoap:operation soapAction=""/>

<wsdl:input name="getArrayBeanRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>

<wsdl:output name="getArrayBeanResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="HelloWorldArrayService">

<wsdl:port binding="impl:GetArraySoapBinding" name="GetArray">
<wsdlsoap:address location="http://localhost:8080/AxisTest/services/GetArray"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

解决方案 »

  1.   

    最近也遇到同样的问题,需要cxf调用axis1的webservice,但是我使用cxf的wsdl2java工具生成客户端代码时,提示:
           "WSDLToJAVA Error:Rpc/encoded wsdls are not supported with CXF"
    这个情况让人很崩溃。请问楼主是怎么生成cxf的客户端的?
      

  2.   

    补充一下,我测试的是如何使用cxf调用 rpc/encoded格式的客户端,并不是针对axis。另附上wsdl文件
    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions targetNamespace="http://order.crm.deppon.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://order.crm.deppon.com" xmlns:intf="http://order.crm.deppon.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!--WSDL created by Apache Axis version: 1.4
    Built on Apr 22, 2006 (06:55:48 PDT)-->
     <wsdl:types>
      <schema targetNamespace="http://order.crm.deppon.com" xmlns="http://www.w3.org/2001/XMLSchema">
       <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
       <complexType name="Order">
        <sequence>
         <element name="goodName" nillable="true" type="xsd:string"/>
         <element name="id" nillable="true" type="xsd:string"/>
         <element name="number" nillable="true" type="xsd:string"/>
         <element name="status" nillable="true" type="xsd:string"/>
        </sequence>
       </complexType>
      </schema>
     </wsdl:types>   <wsdl:message name="getStatusResponse">      <wsdl:part name="getStatusReturn" type="xsd:string">      </wsdl:part>   </wsdl:message>   <wsdl:message name="getStatusRequest">      <wsdl:part name="number" type="xsd:string">      </wsdl:part>   </wsdl:message>   <wsdl:message name="getOrderRequest">      <wsdl:part name="number" type="xsd:string">      </wsdl:part>   </wsdl:message>   <wsdl:message name="getOrderResponse">      <wsdl:part name="getOrderReturn" type="impl:Order">      </wsdl:part>   </wsdl:message>   <wsdl:portType name="OrderService">      <wsdl:operation name="getOrder" parameterOrder="number">         <wsdl:input message="impl:getOrderRequest" name="getOrderRequest">       </wsdl:input>         <wsdl:output message="impl:getOrderResponse" name="getOrderResponse">       </wsdl:output>      </wsdl:operation>      <wsdl:operation name="getStatus" parameterOrder="number">         <wsdl:input message="impl:getStatusRequest" name="getStatusRequest">       </wsdl:input>         <wsdl:output message="impl:getStatusResponse" name="getStatusResponse">       </wsdl:output>      </wsdl:operation>   </wsdl:portType>   <wsdl:binding name="OrderServiceSoapBinding" type="impl:OrderService">      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>      <wsdl:operation name="getOrder">         <wsdlsoap:operation soapAction=""/>         <wsdl:input name="getOrderRequest">            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://order.crm.deppon.com" use="encoded"/>         </wsdl:input>         <wsdl:output name="getOrderResponse">            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://order.crm.deppon.com" use="encoded"/>         </wsdl:output>      </wsdl:operation>      <wsdl:operation name="getStatus">         <wsdlsoap:operation soapAction=""/>         <wsdl:input name="getStatusRequest">            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://order.crm.deppon.com" use="encoded"/>         </wsdl:input>         <wsdl:output name="getStatusResponse">            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://order.crm.deppon.com" use="encoded"/>         </wsdl:output>      </wsdl:operation>   </wsdl:binding>   <wsdl:service name="OrderServiceService">      <wsdl:port binding="impl:OrderServiceSoapBinding" name="OrderService">         <wsdlsoap:address location="http://localhost:8080/axisStudy/services/OrderService"/>      </wsdl:port>   </wsdl:service></wsdl:definitions>