.NET重载WebMethods-可能吗? [英] .NET Overload WebMethods - Possible?

查看:99
本文介绍了.NET重载WebMethods-可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重载两种Web方法:

I have two web methods which I wish to overload:

<WebMethod()> _
Public Function GetProject(ByVal id As Int32) As Project

<WebMethod(MessageName:="GetProjects")> _
Public Function GetProject(ByVal filter As String) As Projects

我读到有关使用MessageName重载的信息,但是我无法使它正常工作.这可能吗?

I read about overloading using MessageName, however I cannot get this to work. Is this possible?

推荐答案

当然可以!

不要忘记更改WebServiceBinding [WebServiceBinding(ConformsTo = WsiProfiles.None)]

do not forget to change the WebServiceBinding [WebServiceBinding(ConformsTo = WsiProfiles.None)]

尝试一下:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[System.ComponentModel.ToolboxItem(false)]    
public class Service : System.Web.Services.WebService
{

    [WebMethod(MessageName = "GetTime")]
    public string GetTime()
    {
        return DateTime.Now.ToShortTimeString();
    }

    [WebMethod(MessageName = "GetTimeWithName")]
    public string GetTime(string userName)
    {
        return "Hello " + userName + " it is " + DateTime.Now.ToShortTimeString();
    }

    [WebMethod(MessageName = "GetTimeWithNameAndRepetitions")]
    public string GetTime(string userName, int repetitions)
    {
        string response = string.Empty;
        for(int i=0; i<repetitions; i++)
            response +=  "Hello " + userName + " it is " + DateTime.Now.ToShortTimeString() + "\n";
        return response;
    }
}

这篇关于.NET重载WebMethods-可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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