如何将ASP.NET方法转换为ASP.NET .asmx Web服务

时间:2016-12-30 13:57:38

标签: c# asp.net web-services web

我有以下asp.net方法,我想将其转换为.asmx web服务。我怎么能这样做请帮忙。

public ActionResult AddCpty(string Id, string Type)
{
    //code for Addcp
    return result;
}

我试图通过在方法顶部放置[WebMethod]属性来转换它。

[WebMethod]
public ActionResult AddCpty(string Id, string Type)
{
    //code for Addcp
    return result;
}

2 个答案:

答案 0 :(得分:0)

尝试使用静态

[WebMethod] 
public static ActionResult AddCpty(string Id, string Type) { 
//code for Addcp return result; 
}

答案 1 :(得分:0)

假设您尝试从ASP模板中访问它,也许您还没有注册路线?

See this link并找到您的项目中注册路线的任何地方以公开该方法。