我们可以在Web服务类中实现方法重载吗? [英] Can we implement method overloading in web service class?
问题描述
我想在Java Web服务类中实现方法重载,如下所示:
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]);
}
}
如果我转发一个用户
对象 myMethod()
,它应该触发第一个方法,如果我发送一个用户$的数组c $ c> s,它应该触发第二种方法。
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.
在WSDL文件中,它只显示一个方法。但是,如果我尝试为两个调用调用 @WebMethod(operationName =)
,我将无法生成WSDL文件。
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.
推荐答案
操作重载不允许用于Web服务。
它是在 WS-BP 和 WSDL 1.2 也不允许它。
即使你发现有一些支持的堆栈我建议不来遵循这种方法。
重载是一个 OO
概念。不要试图将它们应用于面向服务
范例
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
这篇关于我们可以在Web服务类中实现方法重载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!