2014-04-01 79 views
0

我创建了一组3个Java JAX-WS Web服务,每个Web服务都生成自己的WSDL文件,但它们都包含在同一个项目& Web应用程序中。Webservice命名空间共享

它们共享许多相同的请求/响应对象。例如,所有请求&响应对象都从BaseRequest和BaseResponse类继承。

当我使用C#.NET创建一个客户端时,它创建了多个BaseRequest和BaseResponse类,每个WSDL文件一个,但我真正喜欢它的只是创建一组共享的BaseRequest和BaseResponse类。

看来,如果我使所有单独的Web服务共享相同的目标名称空间,我就可以完成此操作。我的问题是,这是否可以接受&(在多个生成不同WSDL文件的Web服务中共享相同的名称空间)?

下面是一些例子Java代码,这样你就可以排序得到的我的web服务如何看待的想法:

@WebService(name = "BasicServicePortType", targetNamespace = "http://com.vectren.ws.basic.impl") 
public interface BasicService 
{ 
    @ResponseWrapper(localName = "LogInResponseWrapper") 
    public LogInResponse logIn(@WebParam(name="request")LogInRequest request); 

    @ResponseWrapper(localName = "LogOutResponseWrapper") 
    public LogOutResponse logOut(@WebParam(name="request")LogOutRequest request); 
} 


@WebService(name = "ContentServicePortType", targetNamespace = "http://com.vectren.ws.content.impl") 
public interface ContentService 
{ 
    @ResponseWrapper(localName = "GetContentResponseWrapper") 
    public GetContentResponse getContentList(@WebParam(name="request")GetContentRequest request); 
} 

@WebService(name = "OutageServicePortType", targetNamespace = "http://com.vectren.ws.outage.impl") 
public interface OutageService 
{ 
    @ResponseWrapper(localName = "GetOutageNumbersResponseWrapper") 
    public GetOutageNumbersResponse getOutageNumbers(@WebParam(name="request")GetOutageNumbersRequest request); 

    @ResponseWrapper(localName = "GetOutageableAccountsByAccountNumbersResponseWrapper") 
    public GetOutageableAccountsResponse getOutageableAccountsByAccountNumbers(@WebParam(name="request")GetOutageableAccountsByAccountNumbersRequest request); 
} 

注:在每一种情况下,请求/响应对象都来自同一个继承“ BaseRequest“/”BaseResponse“类。例如,LogInRequest,LogOutRequest,GetContentRequest,GetOutageNumbersRequest,& GetOutageableAccountsByAccountNumbersRequest 都从BaseRequest继承。响应对象的想法相同。

回答

1

然而,我认为你真正想要的是类型的命名空间是相同的。 服务的命名空间实际上并不重要。只要这些类型有一个通用的命名空间,就可以达到某种程度的通用性。

我不能说.NET,但在Java世界中,三个独立WSDL的wsimport将生成三组代码。但是,如果这些类型位于WSDL /模式中的公共名称空间中,则三次中的两次生成相同的相同代码。如果从三个WSDL生成到同一个客户端项目(jar,war等)中,应该导致两次覆盖常见的代码位。

在您的常用类中,您可以注释它们以具有特定的xml名称空间。如果我记得,不这样做会导致它们在生成的WSDL关联的XSD中的服务的名称空间中声明。

package com.example.services.base; 

@XmlRootElement 
@XmlType(namespace="http://services.example.com/base") 
public class BaseRequest { 
//... 
}