我们可以在Web服务类中实现方法重载吗? [英] Can we implement method overloading in web service class?

查看:125
本文介绍了我们可以在Web服务类中实现方法重载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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(),它应该触发第一个方法,如果我发送一个用户 s,它应该触发第二种方法。

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.

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆