【问题标题】:Webservice not found by Ajax-RequestAjax-Request 未找到 Web 服务
【发布时间】:2026-02-21 17:25:01
【问题描述】:

我的 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)

其实我不明白为什么它有问题?

【问题讨论】:

    标签: jquery asp.net ajax web-services


    【解决方案1】:

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

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

    【讨论】:

    • 哇,谢谢... 好像我需要它在 aspx 端之前我将它迁移到 web 服务,不知道静态是不允许的。谢谢!!