首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.NET过载WebMethods -可能吗?

.NET过载WebMethods -可能吗?
EN

Stack Overflow用户
提问于 2010-10-13 14:00:47
回答 2查看 4.5K关注 0票数 5

我有两个想要重载的web方法:

代码语言:javascript
复制
<WebMethod()> _
Public Function GetProject(ByVal id As Int32) As Project

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

我读到过关于使用MessageName重载的文章,但是我不能让它工作。这个是可能的吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-27 18:12:43

当然,这是可能的!

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

试试这个:

代码语言:javascript
复制
[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;
    }
}
票数 10
EN

Stack Overflow用户

发布于 2010-10-13 18:25:18

是的,这应该是可能的。希望这个链接能有所帮助:http://forums.asp.net/t/1162934.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3921142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档