Web Service method name is not valid

后端 未结 8 2972
余生分开走
余生分开走 2021-02-20 04:39

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

System.InvalidOperationException: SaveBO

相关标签:
8条回答
  • 2021-02-20 04:53

    In my case the error was that the Web Service method was declared "private" instead of "public"

    0 讨论(0)
  • 2021-02-20 05:01

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

    0 讨论(0)
  • 2021-02-20 05:05

    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)

    0 讨论(0)
  • 2021-02-20 05:05

    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.

    0 讨论(0)
  • 2021-02-20 05:06

    As Sundar Rajan states, check the parameters are also correct. My instance of this error was because I had failed to pass any parameters (as a body in a POST request) and the asmx web method was expecting a named parameter, because of this the binding logic failed to match up the request to the method name, even though the name itself is actually correct.

    [WebMethod]
            public object MyWebMethod(object parameter)
    

    If there is no parameter in the body of the request then you will get this error.

    0 讨论(0)
  • 2021-02-20 05:08

    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 "";
         }
    
    0 讨论(0)
提交回复
热议问题