我的WebService有一个Ajax请求:
JS:
$.ajax(
{
type: "POST",
url: "GetProcess.asmx/GetProcessID",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (response) {
//much code here, not needed here
代码隐藏(GetProcess.asmx):
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class GetProcess : System.Web.Services.WebService
{
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static Classes.Progress GetProcessID()
{
Classes.Progress progress = new Classes.Progress();
//Alot of code here also. But i dont think this has todo anything with my problem.
}
}
错误的一小部分,完整可以在这里找到:http://pastebin.com/z3wmFX3P
[ArgumentException]: Unknown web method GetProcessID.
Parameter name: methodName
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)
at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
实际上我不明白它为什么会出现问题?
答案 0 :(得分:1)
问题是您的Web方法被声明为静态。这是不允许的 - 通过Web服务中的Web方法设计应该是实例方法。所以它应该是:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Classes.Progress GetProcessID()