Web服务方法的名称是无效 [英] Web Service method name is not valid

查看:3216
本文介绍了Web服务方法的名称是无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下错误Web服务方法的名称是无效当我试图从JavaScript调用的WebMethod

I get the following error "Web Service method name is not valid" when i try to call webmethod from javascript

System.InvalidOperationException:SaveBOAT We​​b服务方法名无效。
     在System.Web.Services.Protocols.HttpServerProtocol.Initialize()
     在System.Web.Services.Protocols.ServerProtocol.SetContext(类型类型,HttpContext的背景下,Htt的prequest请求的Htt presponse响应)
     在System.Web.Services.Protocols.ServerProtocolFactory.Create(类型类型,HttpContext的背景下,Htt的prequest请求的Htt presponse响应,布尔和放大器; abortProcessing)

System.InvalidOperationException: SaveBOAT Web Service method name is not valid. at System.Web.Services.Protocols.HttpServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

HTML code:

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

JS code:

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);
                }
            });
}

C#code(在AllService.asmx文件Web方法)

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

我试图对堆栈溢出和ASP.NET中的所有解决方案site.but他们没有为我工作。

I tried all solutions found on Stack Overflow and ASP.NET site.but none of them worked for me.

推荐答案

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

It was a silly mistake. remove "Static" from method declaration.

[WebMethod]
     public string SaveBOAT(string Pid)
     {        
      SessionManager.MemberID = Pid;
      return "";
     }

这篇关于Web服务方法的名称是无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆