Web服务方法名称无效

rav*_*dev 10 javascript asp.net jquery

当我尝试从javascript调用webmethod时,我收到以下错误"Web服务方法名称无效"

System.InvalidOperationException:SaveBOAT Web服务方法名称无效.在在System.Web.Services.Protocols.ServerProtocolFactory System.Web.Services.Protocols.HttpServerProtocol.Initialize()在System.Web.Services.Protocols.ServerProtocol.SetContext(类型类型,HttpContext的上下文中,请求的HttpRequest,HttpResponse对象响应). Create(Type type,HttpContext context,HttpRequest request,HttpResponse response,Boolean&abortProcessing)

HTML代码:

<asp:LinkButton runat="server" ID="lnkAddBoat" OnClientClick="javascript:AddMyBoat(); return false;"></asp:LinkButton>
Run Code Online (Sandbox Code Playgroud)

JS代码:

function AddMyBoat() {
            var b = document.getElementById('HdnControlId').value;

            jQuery.ajax({
                type: "GET",
                url: "/AllService.asmx/SaveBOAT",
                data: { Pid: b },
                contentType: "application/text",
                dataType: "text",
                success: function(dd) {
                    alert('Success' + dd);
                },
                error: function(dd) {
                    alert('There is error' + dd.responseText);
                }
            });
}
Run Code Online (Sandbox Code Playgroud)

C#代码(AllService.asmx文件中的Web方法)

[WebMethod]
public static string SaveBOAT(int Pid)
{
    // My Code is here
    //I can put anythng here
    SessionManager.MemberID = Pid;
    return "";
}
Run Code Online (Sandbox Code Playgroud)

我尝试了在Stack Overflow和ASP.NET站点上找到的所有解决方案.但是它们都没有为我工作.

rav*_*dev 13

这是一个愚蠢的错误.从方法声明中删除"静态".

[WebMethod]
public string SaveBOAT(string Pid)
{        
     SessionManager.MemberID = Pid;
     return "";
}
Run Code Online (Sandbox Code Playgroud)


Mat*_*ock 7

就我而言,我复制了另一个 asmx 文件,但未将类属性更改为 asmx 文件本身中新类的名称(右键单击 asmx 文件 -> 查看标记)