Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 574
krig Avatar asked Sep 03 '10 14:09

krig


2 Answers

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

like image 78
Victor Stafusa Avatar answered Oct 21 '22 12:10

Victor Stafusa


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.

like image 1
rbhojan Avatar answered Oct 21 '22 11:10

rbhojan