【问题标题】:.NET Overload WebMethods - Possible?.NET 重载 WebMethods - 可能吗?
【发布时间】:2010-10-13 06:00:47
【问题描述】:

我有两个希望重载的网络方法:

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

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

我阅读了有关使用 MessageName 进行重载的信息,但是我无法让它工作。这可能吗?

【问题讨论】:

    标签: .net web-services overloading webmethod


    【解决方案1】:

    当然有可能!

    不要忘记更改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;
        }
    }
    

    【讨论】:

      【解决方案2】:

      是的,应该可以。 希望此链接对您有所帮助:http://forums.asp.net/t/1162934.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-25
        • 2022-10-07
        • 2010-10-06
        • 2016-09-12
        • 2011-05-19
        • 1970-01-01
        相关资源
        最近更新 更多