返回wsimport生成的服务存根方法中的类型

时间:2014-01-14 15:00:34

标签: wsdl jax-ws wsimport

以下是wsimport生成的服务存根方法的示例:

    @WebMethod(operationName = "GetSynonym", action = "GetSynonymRequest")
    @WebResult(name = "Synonyms", targetNamespace = "service.bnsf.com/contact/ContactMessages")
    @RequestWrapper(localName = "GetSynonym", targetNamespace = "service.bnsf.com/contact/ContactMessages", className = "com.bnsf.service.contact.contactmessages.GetSynonymRequest")
    @ResponseWrapper(localName = "GetSynonymResponse", targetNamespace = "service.bnsf.com/contact/ContactMessages", className = "com.bnsf.service.contact.contactmessages.GetSynonymResponse")
    public Synonyms getSynonym(
            @WebParam(name = "RequestContext", targetNamespace = "service.bnsf.com/contact/ContactMessages") RequestContext requestContext,
            @WebParam(name = "SynonymId", targetNamespace = "service.bnsf.com/contact/ContactMessages") EntityId synonymId)
            throws BusinessFaultMessage, ServiceFaultMessage;

请注意,返回类型是同义词类。

以下是相关的wsdl部分:

<xs:element name="GetSynonymResponse" type="GetSynonymResponse"/>
<xs:complexType name="GetSynonymResponse">
    <xs:sequence>
        <xs:element maxOccurs="1" minOccurs="1" name="Synonyms" type="account:Synonyms"/>
    </xs:sequence>
</xs:complexType>
...
<wsdl:message name="GetSynonymResponse">
    <wsdl:part element="msg:GetSynonymResponse" name="GetSynonymResponse"/>
</wsdl:message>
...
<wsdl:operation name="GetSynonym">
    <soap:operation soapAction="GetSynonymRequest" style="document"/>
    <wsdl:input name="GetSynonymRequestRequest">
        <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output name="GetSynonymRequestResponse">
        <soap:body use="literal"/>
    </wsdl:output>
    <wsdl:fault name="BusinessFault">
        <soap:fault name="BusinessFault" use="literal"/>
    </wsdl:fault>
    <wsdl:fault name="ServiceFault">
        <soap:fault name="ServiceFault" use="literal"/>
    </wsdl:fault>
</wsdl:operation>

默认情况下,wsimport生成的服务方法使用Synonyms类作为返回类型而不是GetSynonymResponse类。

我的问题是这是否可以自定义 - 是否有可能使wsimport生成具有不同签名的服务方法,特别是将GetSynonymResponse类作为返回类型?

提前致谢,

瓦列

1 个答案:

答案 0 :(得分:2)

了解这是如何配置的:

该功能名为&#34; WrapperStyle&#34;应禁用以使生成的方法返回xxxResponse类型。 这可以通过向wsimport提供-b参数来实现,如

  

的wsimport&#34; -b binding.xml ContactService.wsdl

将binding.xml内容作为

<jaxws:bindings wsdlLocation="ContactService.wsdl"
                                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                                xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
                                xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
                    <!-- Turn off wrapper style Java method signature generation -->
                    <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>