.NET Overload WebMethods - Possible?
Asked Answered
T

2

5

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

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

Ta answered 13/10, 2010 at 6:0 Comment(0)
S
10

Off course it is possible!

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

try this:

[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;
    }
}
Stinson answered 27/4, 2012 at 10:12 Comment(0)
K
1

Yes, it should be possible. Hope this link will help: http://forums.asp.net/t/1162934.aspx

Knownothing answered 13/10, 2010 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.