本文介绍了编译多个共享公共模式的 WSDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个网络服务.两者都是由应用程序实现的,因此有一些共同的对象.我有一个 GWT 前端,它使用这两个网络服务.在这里,当我使用 maven wsimport 生成 webserive 类时.我在两个不同的包中得到了这些相同类的重复项.我不想创建这些类的重复项.因此创建了这些类的绑定.但是每次网络服务发生任何变化时.我已经调整了绑定中定义的类,我想避免这种情况.

I have two webservices. Both are implemented by an application and hence have some common objects. And I have a GWT frontend which uses both of the webservices. And here, when I generate webserive classes using maven wsimport. I get duplicates of these same classes in two different packages. I don't want to create duplicates of these classes. So created bindings of these classes. But everytime anything changes in the webservice. I have adapt the classes defined in bindings, which i would like to avoid.

我的问题是.有没有更好的方法来处理这些常见的类?

My question would be. Is there a better way to handle these common classes?

推荐答案

完全有可能在两个或多个 Web 服务上使用公共 bean.您只需要在由两个服务导入的 xsds 中声明您的类型.例如,考虑这个名为 Common.xsd 的 xsd,包含一些服务的通用类型

It is entirely possible to have common beans on two or more web services. You just need to declare your types in xsds that are imported by both services. For example, consider this xsd, named Common.xsd, containing common types for some services

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                         xmlns:tns="http://www.foo.com/ws/common"
                         targetNamespace="http://www.foo.com/ws/common"
                         elementFormDefault="qualified">

    <xsd:element name="Address" type="tns:Address"/>
    <xsd:element name="MyWsFault" type="tns:MyWsFault" />

    <xsd:complexType name="Address">
        <xsd:sequence>
            <xsd:element name="city" type="xsd:string" minOccurs="0"/>
            <xsd:element name="country" type="xsd:string" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="MyWsFault">
        <xsd:sequence>
            <!-- whatever you want to encapsulate in case of an error -->
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

现在对于类型 Address 将有一个使用完全限定名称 com.foo.ws.common.Address 生成的单个类

Now for the type Address there will be a single class generated with fully qualified name com.foo.ws.common.Address

为了完整起见,请考虑以下返回地址的服务(为简单起见,未指定输入).

For completeness sake, consider the following service returning an Address (for simplicity the input is left unspecified).

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:cmn="http://www.foo.com/ws/common"  
                  xmlns:tns="http://www.foo.com/ws"
                  targetNamespace="http://www.foo.com/ws">

    <wsdl:types>
        <xsd:schema>
            <xsd:import namespace="http://www.foo.com/ws/common" schemaLocation="Common.xsd" />
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="GetAddressRequest">
        <!-- request input here -->
    </wsdl:message>

    <wsdl:message name="GetAddressResponse">
        <wsdl:part name="Address" element="cmn:Address" />
    </wsdl:message>

    <wsdl:message name="MyWsException">
        <wsdl:part name="MyWsFault" element="cmn:MyWsFault" />
    </wsdl:message>

    <wsdl:portType name="GetAddressPortType">
        <wsdl:operation name="GetAddress">
            <wsdl:input message="tns:GetAddressRequest" name="GetAddressRequest"/>
            <wsdl:output message="tns:GetAddressResponse" name="GetAddressResponse"/>
            <wsdl:fault message="tns:MyWsException" name="MyWsException"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="GetAddressBinding" type="tns:GetAddressPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="GetAddress">
            <soap:operation soapAction="GetAddress"/>
            <wsdl:input name="GetAddressRequest">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="GetAddressResponse">
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="MyWsException">
                <soap:fault name="MyWsException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="GetAddressService">
        <wsdl:port binding="tns:GetAddressBinding" name="GetAddressPort">
            <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

IIRC 在 Spring 上有一个关于契约优先 Web 服务的非常好的资源,您可能需要检查一下.

IIRC there is a pretty good resource on Spring for contract first web services, which you might want to check.

这篇关于编译多个共享公共模式的 WSDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 15:52