Publishing multiple ports with one service using JAX-WS 2.0 and @WebService
Asked Answered
C

3

13

I want to create a SOAP service with multiple port types exposed, where each port type has a separate interface. I'm trying to do this using JAX-WS 2.0.

Example:

interface A:
    ObjectA get(String name);

interface B:
    ObjectB get(String name);

Service:
    port A
          get
    port B
          get

The problem I'm having is that an @WebService is defined using a single class/interface, so the only way I'm able to set this up is having two separate services. Each service implemented by a separate class with a @WebService annotation.

I'd like to expose both ports using the same service, to make it clear that both of them are part of the same API. Is this possible?

Really, what I'm after is having some kind of nested namespace support in the WSDL, so I can have the same methods in different namespaces. I'll have get/set/delete methods for different kinds of data next to each other, but I'd rather not put them all in the same big interface with getA/getB and so on, since I'd like to be able to add new data types later on without forcing all the clients to regenerate from the new set of WSDLs. Any tips on achieving this are welcome, even if it means using another way of generating the WSDL from java code.

Caffeine answered 3/9, 2010 at 14:17 Comment(0)
S
1

You may try to rename one of the methods and set the action or operationName fields in the @WebMethod annotation explicitly.

Scots answered 28/12, 2010 at 22:21 Comment(0)
B
1

I would suggest instead of defining the input parameter as a String, you should consider defining a RequestType (a complextype in xsd), for each of those methods and that would give you the following advantages:
1. If you have a defined complex type, then the request can evolve independenty where you add more elements in the complex type, while the web method signature does not change in the wsdl.
2. You can have the same name for the 2 methods like u have above (say get(...)), while both of them will have the different request types. You can achieve this either by defining the two different elements in the xsd (with same namespace) with different request names. If you want to have the same name for the request elements, then you must consider defining them in different namespaces. That way in OOP, they will be generated in different packages and therefore they can have the same name.

On a different note, I would suggest that it is always good to have your operation names and the message names as unique and specific as possible.

Byssus answered 17/12, 2013 at 20:36 Comment(0)
B
0

Function overloading will not be accepted in Webservices. I mean multiple operation with same name can not be done. You need same port and same operation name to return different class Object, you can try the following.

interface

public interface OB {
public Object get(String name);
}

Webservice

@Override
@WebMethod
public Object get(String name) {
    if(name.equals("A")){
        return new ObjectA("A");
    }else if(name.equals("B")){
        return new ObjectB(1);
    }else {
        return null;
    }
}

In this case you have to identify which class object need to be returned from the request and then construct it and returning back is one of the way.

Brachial answered 2/5, 2014 at 6:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.