2010-10-13 10 views
5

Mam dwie metody internetowych, które pragnę przeciążeniem:.NET Overload WebMethods - Możliwe?

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

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

Czytałem o przeciążeniu za pomocą MessageName, jednak nie mogę uzyskać to do pracy. czy to możliwe?

Odpowiedz

10

Oczywiście, że jest to możliwe!

Nie zapomnij zmienić WebServiceBinding [WebServiceBinding(ConformsTo = WsiProfiles.None)]

spróbować tego:

[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; 
    } 
} 
Powiązane problemy