2010-10-13 12 views
5

मैं दो वेब तरीकों जो मैं अधिभार करना चाहते हैं:.NET ओवरलोड वेबमाइड्स - संभव है?

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

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

मैं MessageName का उपयोग कर अधिक भार के बारे में पढ़ा है, तथापि मैं इस काम करने के लिए नहीं मिल सकता है। क्या यह संभव है?

उत्तर

10

बेशक यह संभव है!

मत भूलना 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; 
    } 
} 
संबंधित मुद्दे