JavaScript Web Service method name is not valid service method name is not valid,web service method name

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

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 (Web method in AllService.asmx file)

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

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

Answer:1

It was a silly mistake.

remove Static keyword from method declaration.

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

Try using this, I think datatype should be JSON

       jQuery.ajax({
            type: "POST",  // or GET
            url: "/AllService.asmx/SaveBOAT",
            data: { Pid: b },
            contentType: "application/json; charset=utf-8",
            dataType: "json"
            success: function(dd) {
                alert('Success' + dd);
            },
            error: function(dd) {
                alert('There is error' + dd.responseText);
            }
        });

And in C# Code change Pid to string

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

I too faced the similar issue. The solution includes checking everything related to ensuring all name, parameters are passed correctly as many have responded. Make sure that the web method name that we are calling in UI page is spelled correctly, the data, data types are correct and etc. In my case, I misspelled the web method name in my ajax call. It works fine once I found and corrected the name correctly.
For Ex: In .asmx class file, this is the method name "IsLeaseMentorExistWithTheSameName" but when I called from UI this is how I called:

var varURL = <%=Page.ResolveUrl("~/Main/BuildCriteria.asmx") %> + '/IsLeaseMentorExistWithSameName';  

Notice that the word "The" is missing. That was a mistake and I corrected and so it worked fine.

Answer:4

In my case I had copied another asmx file, but not changed the class property to the name of the new class in the asmx file itself (Right click on asmx file -> View Markup)

Answer:5

Did U add ServiceReference Class. Check this once. Based on your comment I can tell what to do

Answer:6

I had this issue because my soap method had a List<string> parameter. Couldn't figure out a way to make it work with the array parameter; so just converted the parameter to a &-delimited string (e.g. val1&val2&val3) and converted the parameter to an array in the service method.

Answer:7

I have code like the following: function test(obj) { if(//some conditon) { obj.onload(); }else{ obj.onerror(); } } for(var i=0;i<4;i++){ test({ onload:...

I have code like the following: function test(obj) { if(//some conditon) { obj.onload(); }else{ obj.onerror(); } } for(var i=0;i<4;i++){ test({ onload:...

In Three.js, I would like to use THREE.quaternion to make the camera object rotate to the selected object. I did search the web but found no example/demo or document about how to use this quaternion ...

In Three.js, I would like to use THREE.quaternion to make the camera object rotate to the selected object. I did search the web but found no example/demo or document about how to use this quaternion ...

  1. three.js rotate camera quaternion
  2. three js camera quaternion
  3. three.js rotate object quaternion

I am creating a popup window that goes to hello.html. I want my original (parent page) to reload when i close the popup window (hello.html). I can't seem to get it to work, but I'm close. Here is ...

I am creating a popup window that goes to hello.html. I want my original (parent page) to reload when i close the popup window (hello.html). I can't seem to get it to work, but I'm close. Here is ...

  1. refresh parent window after closing modal dialog
  2. refresh parent window after closing popup
  3. reload parent window after closing popup
  4. javascript refresh parent window after closing popup
  5. auto refresh parent window after closing popup javascript
  6. refresh parent window after closing child window javascript
  7. refresh parent page after closing popup window
  8. refresh parent page after closing modal dialog

In the IE developer (F12) console, I've managed to get my pages to run without errors; all but one! SCRIPT1002: Syntax error mypage.php, line 1 character 6 I am using IE9. Whats it's problem? ...

In the IE developer (F12) console, I've managed to get my pages to run without errors; all but one! SCRIPT1002: Syntax error mypage.php, line 1 character 6 I am using IE9. Whats it's problem? ...

  1. script1002 syntax error line 1 character 1