【问题标题】:Unmarshalling Error CXF解组错误 CXF
【发布时间】:2015-06-04 10:46:42
【问题描述】:

我使用 IntelliJ 最新版本,JDK 1.7 和 CXF 3.1 我使用这些从 WSDL 生成 Java 客户端代码。

这里是 WSDL

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
    targetNamespace="http://myserver/definitions"
    xmlns:tns="http://myserver/definitions"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:icd="http://myserver/schemas/GlobalID">

    <!-- schema imports + elements -->
    <wsdl:types>
        <xs:schema targetNamespace="http://myserver/definitions">
            <xs:import namespace="http://myserver/schemas/GlobalID" schemaLocation="http://myserver/schemas/GlobalID.xsd" />
        </xs:schema>
    </wsdl:types>

    <!-- message definitions -->
    <wsdl:message name="AddressingRequest">
        <wsdl:part name="Body" element="icd:Addressing" />
    </wsdl:message>
    <wsdl:message name="AddressingResponse">
        <wsdl:part name="Body" element="icd:AddressingResponse" />
    </wsdl:message>


    <!-- ports -->       
    <wsdl:portType name="WebServicePortType">
        <wsdl:operation name="AddressingRequest">
            <wsdl:input message="tns:AddressingRequest" />
            <wsdl:output message="tns:AddressingResponse" />
        </wsdl:operation>
    </wsdl:portType>

    <!-- service bindings -->
    <wsdl:binding name="WebServiceBinding" type="tns:WebServicePortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="AddressingRequest">
            <soap:operation soapAction="Addressing" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <!-- service -->
    <wsdl:service name="GlobalIDWebService">
        <wsdl:port name="WebServicePort" binding="tns:WebServiceBinding">
            <soap:address location="${soap.address.location}"/>
        </wsdl:port>
    </wsdl:service>

    <wsdl:service name="GlobalIDWebServiceSecure">
        <wsdl:port name="SecureWebServicePort" binding="tns:WebServiceBinding">
            <soap:address location="${soap.address.location.secure}"/>
        </wsdl:port>
    </wsdl:service>    

</wsdl:definitions>

还有一些需要的 xsd 定义:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
    elementFormDefault="unqualified" 
    attributeFormDefault="unqualified"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://myserver/schemas/GlobalID"
    xmlns:globalid="http://myserver/schemas/GlobalID"
    xmlns:common="http://myserver/schemas/Common">

    <xs:import namespace="http://myserver/schemas/Common" schemaLocation="http://myserver/schemas/Common.xsd"/>

    <xs:element name="Addressing" type="globalid:AddressingSearchType"/>
    <xs:complexType name="AddressingSearchType">
        <xs:sequence>
            <xs:element name="Authentication" type="common:AuthenticationType" minOccurs="1"
                maxOccurs="1"/>
            <xs:choice>
                <xs:element name="Address" type="common:AddressType" minOccurs="1" maxOccurs="1"/>
                <xs:element name="ComponentAddress" type="globalid:AddressingRecordType"
                    minOccurs="1" maxOccurs="1"/>
                <xs:sequence>
                    <xs:element name="FullAddress" type="xs:string" minOccurs="1" maxOccurs="1"/>
                    <xs:element name="CountryCode" type="common:CountryCodeType" minOccurs="1"
                        maxOccurs="1"/>
                </xs:sequence>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="maxrows" type="xs:integer"/>
    </xs:complexType>

    <xs:element name="AddressingResponse" type="globalid:AddressingResponseType"/>
    <xs:complexType name="AddressingResponseType">
        <xs:sequence>
            <xs:element name="Result" type="globalid:AddressingRecordType" minOccurs="0"
                maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="recordcount" type="xs:integer"/>
    </xs:complexType>


    <xs:complexType name="AddressingRecordType">
        <xs:group ref="globalid:AddressingRecordGroup"/>
    </xs:complexType>


    <xs:group name="AddressingRecordGroup">
        <xs:all>
            <xs:element name="AddressLine1" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="AddressLine2" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="AddressLine3" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="AddressLine4" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="AddressLine5" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="AddressLine6" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="AddressLine7" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="AddressLine8" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="CountryCode" type="common:CountryCodeType" minOccurs="1" maxOccurs="1"/>
        </xs:all>
    </xs:group>

</xs:schema>

我得到错误

org.apache.cxf.interceptor.Fault:解组错误:意外 元素(uri:“http://myserver/schemas/GlobalID”, 本地:“结果”)。预期元素是

我尝试了许多不同的方法,在 POJO 中添加和删除命名空间......但没有任何效果。我在网上搜索到的所有类似的这个问题的解决方案都没有帮助...... :(

【问题讨论】:

    标签: java web-services intellij-idea wsdl cxf


    【解决方案1】:

    看来我需要在 POJO 的注释中定义命名空间...不知道为什么 CXF 没有正确生成它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多