我有两个想要重载的web方法:
<WebMethod()> _
Public Function GetProject(ByVal id As Int32) As Project
<WebMethod(MessageName:="GetProjects")> _
Public Function GetProject(ByVal filter As String) As Projects我读到过关于使用MessageName重载的文章,但是我不能让它工作。这个是可能的吗?
发布于 2012-04-27 18:12:43
当然,这是可能的!
不要忘记更改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;
}
}发布于 2010-10-13 18:25:18
是的,这应该是可能的。希望这个链接能有所帮助:http://forums.asp.net/t/1162934.aspx
https://stackoverflow.com/questions/3921142
复制相似问题