Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we implement method overloading in web service class?

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 Users, 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.

like image 336
user1227035 Avatar asked Apr 25 '12 16:04

user1227035


1 Answers

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

like image 190
Cratylus Avatar answered Nov 12 '22 03:11

Cratylus