gpt4 book ai didi

.NET 重载 WebMethods - 可能吗?

转载 作者:行者123 更新时间:2023-12-04 17:13:13 26 4
gpt4 key购买 nike

我有两个我希望重载的网络方法:

<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;
}
}

关于.NET 重载 WebMethods - 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3921142/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com