JAX-WS:“wsdl:types”下的多个“xsd:schema”,为什么?

时间:2013-12-03 06:14:54

标签: java xsd wsdl jax-ws

我正在尝试用分开的Ednpoint-s编写测试Web服务应用程序,如下所示:

package test;

import ...

public class Main {

    HttpsServer server;
    HashMap<String, Endpoint> endpointMap;

    public Main() {
        try {
            SSLContext ssl = ...
            this.server = HttpsServer.create(
                    new InetSocketAddress("localhost", 8089),
                    8089);
            this.endpointMap = new HashMap();
            endpointMap.put("/test11", Endpoint.create(new SOAPService1()));
            endpointMap.put("/test22", Endpoint.create(new SOAPService2()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void start() {
        server.start();
        for (String uri : endpointMap.keySet()) {
            endpointMap.get(uri).publish(
                    server.createContext(uri));
        }
    }

    public static void main(String[] args) throws Exception {
        new Main().start();
    }
}

结果我在

获得了一个wsdl
https://localhost:8089/test11?wsdl

类型下有多个 xsd:schema

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test1.service.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://test1.service.com" name="TEST1Service">
    <types>
        <xsd:schema>
            <xsd:import namespace="http://test2.service.com" schemaLocation="https://localhost:8089/test11?xsd=1"/>
        </xsd:schema>
        <xsd:schema>
            <xsd:import namespace="http://test1.service.com" schemaLocation="https://localhost:8089/test11?xsd=2"/>
        </xsd:schema>
    </types>
    <message name="test">
        <part name="parameters" element="tns:test"/>
    </message>
    <message name="testResponse">
        <part name="parameters" element="tns:testResponse"/>
    </message>
    <portType name="SOAPService1">
        <operation name="test">
            <input wsam:Action="http://test1.service.com/SOAPService1/testRequest" message="tns:test"/>
            <output wsam:Action="http://test1.service.com/SOAPService1/testResponse" message="tns:testResponse"/>
        </operation>
    </portType>
    <binding name="TEST1PortBinding" type="tns:SOAPService1">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="test">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="TEST1Service">
        <port name="TEST1Port" binding="tns:TEST1PortBinding">
            <soap:address location="https://localhost:8089/test11"/>
        </port>
    </service>
</definitions>

第二个网址上提供的WSDL

https://localhost:8089/test22?wsdl

没有:

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test2.service.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://test2.service.com" name="TEST2Service">
    <types>
        <xsd:schema>
            <xsd:import namespace="http://test2.service.com" schemaLocation="https://localhost:8089/test22?xsd=1"/>
        </xsd:schema>
    </types>
    <message name="test">
        <part name="parameters" element="tns:test"/>
    </message>
    <message name="testResponse">
        <part name="parameters" element="tns:testResponse"/>
    </message>
    <portType name="SOAPServiceInterface2">
        <operation name="test">
            <input wsam:Action="http://test2.service.com/SOAPServiceInterface2/testRequest" message="tns:test"/>
            <output wsam:Action="http://test2.service.com/SOAPServiceInterface2/testResponse" message="tns:testResponse"/>
        </operation>
    </portType>
    <binding name="TEST2PortBinding" type="tns:SOAPServiceInterface2">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="test">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="TEST2Service">
        <port name="TEST2Port" binding="tns:TEST2PortBinding">
            <soap:address location="https://localhost:8089/test22"/>
        </port>
    </service>
</definitions>

我希望他们完全分开而不了解彼此,但正如你所看到的,第一个甚至包括第二个的模式。 我做错了什么?

1 个答案:

答案 0 :(得分:0)

我会回答我自己的问题。 通过使用

注释服务类
@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE)

它删除了额外的XSD并解决了问题