Can we implement method overloading in web service class?

apache-axis, java, jax-ws, wsdl

Solution

Operation overloading is not allowed for web services. It is explicitely prohibited in WS-BP and WSDL 1.2 also disallows it. Even if you found a stack that has some support for this I would recommend not to follow this approach. Overloading is an `OO` concept. Don't try to apply them to `Service Oriented` paradigm

Problem

I would like to implement method overloading in the Java web service class as follows: ``` public String myMethod(User user) { // My code } public String myMethod(User[] user) { for(int i=0; i<user.length; i++) { myMethod(user[i]); } } ``` If I forward a single `User` object to `myMethod()`, it should trigger the first method and if I send an array of `User`s, it should trigger the second method. In the WSDL file it shows only a single method. However, if I try to call `@WebMethod(operationName="")` for both calls, I am unable to generate the WSDL file.

Original source