我已经开始在 ASPX web 项目中工作,该项目已经有一个现有的 asmx
文件。它包含大约 4 个 WebMethods,这 4 个 Webmethods 显示了 http://localhost:2133/WebServices.asmx
现在我尝试添加名为 GetCities
的新 WebMethod 与现有方法非常相似,但它没有在 中显示列表http://localhost:2133/WebServices.asmx
。我试着重新编译它。当我深入检查(服务引用)时,我找不到引用 WebService WebServices.asmx
的位置。
现有方法
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetAvailable(int clientCode)
{
try
{
//Db Querying statements
}
catch (Exception exc)
{
}
}
我添加的新方法
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetCities()
{
try
{
//Db Querying statements
}
catch (Exception exc)
{
}
}
完全困惑,请分享您的想法。
最佳答案
您需要通过执行以下操作来更新用于使用您的网络服务的代理类:
- 在解决方案资源管理器中,打开项目的 App_WebReferences 文件夹,然后单击要更新的 Web 引用的节点。
- 右键单击引用,然后单击“更新 Web 引用”。 XML Web 服务的新文件已下载到您的项目中。 XML Web 服务的信息在您的项目中更新。
关于c# - 如何在 asmx 文件中添加 WebMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18726521/