views:

25

answers:

1

Hi all, i am using Netbeans to create a Web Service and the code is written in java. My problems arises from creating 2 functions that will be accessible by a client. The functions look alike by name but their parameters are different.

When building the web service(int a war file) i get no complaints. However when deploying the war file onto a glassfish server renders errors that would make me conclude that glassfish somehow is getting confused about 2 functions of the same name without looking into the parameter list. Is this a common occurrence and is there a workaround?

For example:

@WebMethod() public Long startMission(@WebParam(name="session") Session session, String name{ ..... }

@WebMethod() public Long startMission(@WebParam(name="session") Session session, Long num{ ..... }

The error on the glassfish server comes back to me and tells me that the 2nd StartMission function does not contain an entry point for parameter @Long num - which tells me that it does not recognize 2 functions of the same name. Perhaps i am thinking about this the wrong way. Any help, options, suggestions would be appreciated. thanks!

A: 

You can distinguish between the two methods by specifying the operation that they correspond to. This is done by specifying the operationName member value for the WebMethod annotation.

For example,

@WebMethod(operationName='startMissionWithName') public Long startMission(@WebParam(name="session") Session session, String name{ ..... }

@WebMethod(operationName='startMissionWithId') public Long startMission(@WebParam(name="session") Session session, Long num{ ..... }
Vineet Reynolds
will the client see the operation name in intellisense causing confusion or will that be hidden from the user internally?
cws
The operation name described in the annotation is the one that is present in the generated (and published) WSDL, unless the client is using a different WSDL document. So, as far the client is concerned, it will now see two distinct operations.
Vineet Reynolds
so then whats the difference in adding the operation name and just make 2 separate function names? it would be nice to give the client the same function name with options on parameters and the execution of code beyond the function call would depend on the parameters passed.
cws
Well, to answer that question, here's another question - how is the container supposed to determine the name of the operation in the generated WSDL, and more importantly, map incoming requests against webmethod annotated methods, if two methods exposed in a service have the same name? You can find that someone has faced similar problems: http://planet.petalslink.com/home/chamerling/2009/05/14/an-operation-with-name-already-exists-in-this-service/
Vineet Reynolds
well i would have hoped that the container, just like a standalone library would be able to decipher the functions beyond just name scope and look at the parameter list - but for some reason this isnt possible. I looked at your link and the solution was what you had given to me - to put in the operationName annotation. But i see really no difference in that and just making the functions have different names, unless i am missing something.
cws