Question

I've created a set of 3 Java JAX-WS web services that each generate their own WSDL file but they are all contained in the same project & web app.

They share many of the same request / response objects. For example all the all of the request & response objects inherit from BaseRequest and BaseResponse classes.

When I create a client using C# .NET it creates multiple BaseRequest and BaseResponse classes, one for each WSDL file, but what I would really like it to do is only create one set of shared BaseRequest and BaseResponse classes.

It seems that I can accomplish this if I make all of my separate web services share the same target namespace. My question is, is this acceptable & appropriate to do (sharing the same namespace among multiple webservices that generate different WSDL files)?

Here's some example Java code so you can sort of get an idea of how my webservices look:

@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);
}

Note: In each of these cases the request / response objects all inherit from the same "BaseRequest" / "BaseResponse" classes. For example, LogInRequest, LogOutRequest, GetContentRequest, GetOutageNumbersRequest, & GetOutageableAccountsByAccountNumbersRequest all inherit from BaseRequest. Same idea for the response objects.

Was it helpful?

Solution

I think however what you really want is for the namespaces of the types to be the same. The namespaces of the services don't really matter all that much. As long as the types have a common namespace you'll achieve some degree of commonality.

I can't speak for .NET, but in the Java world, wsimport of three separate WSDLs will generate three sets of code. However, if the types are in a common namespace across the WSDLs / schemas, then two of the three times generate the same identical code. If generating from the three WSDLs into the same client project (jar, war, etc) should result in overwriting the common bits of code twice.

In your common classes, you can annotate them to have a specific xml namespace. If I recall, not doing so causes them to be declared in the namespace of the service within the generated WSDL's associated XSDs.

package com.example.services.base;

@XmlRootElement
@XmlType(namespace="http://services.example.com/base")
public class BaseRequest {
//...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top