Ajax请求找不到Web服务



我有一个Ajax请求到我的WebService:

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

CodeBehind(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)

事实上,我不明白为什么它有问题?

问题是您的web方法被声明为静态。这是不允许的-根据设计,web服务中的方法应该是实例方法。所以应该是:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Classes.Progress GetProcessID()

相关内容

最新更新