Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

java - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...