我有两个希望重载的 Web 方法:
<WebMethod()> _
Public Function GetProject(ByVal id As Int32) As Project
<WebMethod(MessageName:="GetProjects")> _
Public Function GetProject(ByVal filter As String) As Projects
我阅读了有关使用 MessageName 进行重载的信息,但是我无法使其正常工作。这可能吗?
我有两个希望重载的 Web 方法:
<WebMethod()> _
Public Function GetProject(ByVal id As Int32) As Project
<WebMethod(MessageName:="GetProjects")> _
Public Function GetProject(ByVal filter As String) As Projects
我阅读了有关使用 MessageName 进行重载的信息,但是我无法使其正常工作。这可能吗?
当然有可能!
不要忘记更改 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;
}
}
是的,这应该是可能的。希望这个链接会有所帮助:http ://forums.asp.net/t/1162934.aspx