如何告诉cxf在方法中保留包装器类型?

时间:2014-04-24 13:53:57

标签: java serialization jaxb wsdl cxf

在我的WSDL中,我有一个操作

<wsdl:operation name="theMethod">
    <wsdl:input message="input1" name="input1"></wsdl:input>
    <wsdl:output message="tns:classNumber1" name="classNumber1"></wsdl:output>
</wsdl:operation>

在我的xsd中,classNumber1是一个复杂类型,它是另一种类型的包装:classNumber2

<xs:complexType name="classNumber1">
  <xs:sequence>
   <xs:element minOccurs="0" name="arg0" type="tns:classNumber2"/>
  </xs:sequence>
</xs:complexType>

当我使用cxf生成类时(我使用cxf maven插件),我希望theMethod返回ClassNumber1但它是ClassNumber2

@WebMethod
@ResponseWrapper(localName="classNumber1" , className="com.model.ClassNumber")
public ClassNumber2 theMethod (Input1 input1){
    ...
}

有没有办法告诉cxf使用包装器CLassNumber1生成方法。 感谢。

2 个答案:

答案 0 :(得分:4)

我在这个doc找到解决方案,问题“如何将生成的Web服务方法调用从包装器样式切换到非包装器样式(反之亦然)?

保持包装器生成cxf的解决方案是在pom.xml中添加绑定文件

<defaultOptions>
<bindingFiles>
    <bindingFile>${basedir}/src/main/resources/bindings.xjb</bindingFile>
</bindingFiles>
<noAddressBinding>true</noAddressBinding>
</defaultOptions>

在绑定文件中,您将 enableWrapperStyle 设置为false:

<jaxws:bindings
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns="http://java.sun.com/xml/ns/jaxws"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <enableWrapperStyle>false</enableWrapperStyle>
</jaxws:bindings>

答案 1 :(得分:0)

根据您提供的信息,我创建了一个基本界面,如下所示。

这符合您的期望。

                                       

        <xsd:complexType name="input1">
            <xsd:sequence>
                <xsd:element name="in" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>

        <xsd:complexType name="ClassNumber1">
            <xsd:sequence>
                <xsd:element minOccurs="0" name="out" type="tns:ClassNumber2" />
            </xsd:sequence>
        </xsd:complexType>

        <xsd:complexType name="ClassNumber2">
            <xsd:sequence>
                <xsd:element name="out" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>
</wsdl:types>
<wsdl:message name="input1">
    <wsdl:part element="tns:input1" name="parameters" />
</wsdl:message>
<wsdl:message name="ClassNumber1">
    <wsdl:part element="tns:ClassNumber1" name="parameters" />
</wsdl:message>
<wsdl:portType name="NewWSDLFile">
    <wsdl:operation name="NewOperation">
        <wsdl:input message="tns:input1" />
        <wsdl:output message="tns:ClassNumber1" />
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="NewWSDLFileSOAP" type="tns:NewWSDLFile">
    <soap:binding style="document"
        transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="NewOperation">
        <soap:operation soapAction="http://www.example.org/NewWSDLFile/NewOperation" />
        <wsdl:input>
            <soap:body use="literal" />
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal" />
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="NewWSDLFile">
    <wsdl:port binding="tns:NewWSDLFileSOAP" name="NewWSDLFileSOAP">
        <soap:address location="http://www.example.org/" />
    </wsdl:port>
</wsdl:service>

请检查<wsdl:output message="tns:ClassNumber1" />

我相信您在

中的输出信息中出错了
<wsdl:message name="ClassNumber1">
            <wsdl:part element="tns:ClassNumber1" name="parameters" />
        </wsdl:message>

希望这有帮助。