Unknown web method. Parameter name: methodName

40,497

Solution 1

I had a problem in the actual .aspx file, the line

<%@ Page Language="C#" 
         AutoEventWireup="true" 
         CodeBehind="xxx.xxx.cs" Inherits="xxx.xxx" %>

wasn't present in the code. How did it get changed? I Don't know :(.

Solution 2

I had this issue as well, but slightly differently I had this method in a .asmx file and so ran across the "static" issue, but in a different way.

If you have a method as part of your Page class, it must be static.

If you've put a method in an .asmx file to use across several pages, it must not be static.

Solution 3

For me, the primary issues was to change javascript post to pass in no arguments such as

$http.post("Status.aspx/MyData", {})

Then to verify nothing was cached, I then deleted [System.Web.Services.WebMethod] in the code behind file above public static string MyData(). Then I built the project to failure, then re-added the aformentioned deleted attribute and built to success.

Upon running it worked.

Solution 4

Missing the [WebMethod] above your server side function will also cause this error.

Solution 5

To be honest, I've just realised "again" how tired we could be in some cases.

For me it was just a private method instead of a public one.

Share:
40,497
Daniel Sh.
Author by

Daniel Sh.

Amazing site.

Updated on September 21, 2020

Comments

  • Daniel Sh.
    Daniel Sh. almost 4 years

    In researching this problem most SO issues were about the static method as a fix.

    Since it's not working with the real (and a bit sophisticated) WebMethod I've just created a simple one for the sake of checking if reaching the method itself is possible.

    [WebMethod]
    [ScriptMethod(UseHttpGet = false)]
    public static string HelloWorld()
    {
        return "Hello World!";
    }
    

    The call.

    <script>
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "usersWebMethods.aspx/HelloWorld",
                dataType: "json",
                success: function (data) {
                    alert(data.d);
                }
            });
       });
    </script>
    

    It always comes down to 500 (Internal Server Error)

    Unknown web method HelloWorld.
    Parameter name: methodName
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    Exception Details: System.ArgumentException: Unknown web method HelloWorld.
    Parameter name: methodName
    

    Why is this failing?

    • James
      James over 10 years
      static web methods are not supported.
    • Daniel Sh.
      Daniel Sh. over 10 years
      maybe I got it all wrong or I haven't explained myself properly. This is just an .aspx page using webmethods in the codebehind. It's not a webservice.
    • James
      James over 10 years
      Ah ok, are you using a ScriptManager? If so do you have the EnableScriptMethods enabled?
    • Daniel Sh.
      Daniel Sh. over 10 years
      No, just using jQuery, I was sure there's no need to use a ScriptManager
    • James
      James over 10 years
      no you shouldn't have to, I am just trying to gauge your setup. Which page are you running the JS from?
    • Daniel Sh.
      Daniel Sh. over 10 years
      And I thank you for your time! Originally I intend to call the methods from a .html page, but for the sake of testing I'm just running the JS from the .aspx page itself, usersWebMethods.aspx in my case.
    • James
      James over 10 years
      No worries, have you tried passing an empty data param? i.e. data: "{}"?
    • Daniel Sh.
      Daniel Sh. over 10 years
      that I also tried, same result. Right now I'm playing with Fiddler to see if I can dig a bit more, no good outcome yet.
    • James
      James over 10 years
      Code looks good from what I can see, it is as though the web method has not been exposed. Have you tried cleaning/re-building the site?
    • Daniel Sh.
      Daniel Sh. over 10 years
      Same, don't know what else to try :/
    • James
      James over 10 years
      Hmm my initial incling was the URL was wrong, could you try something like url: window.location.href + "/HelloWorld"?
    • Daniel Sh.
      Daniel Sh. over 10 years
      Same :/ it's not being accesed at all.
    • James
      James over 10 years
      I'd opt for going for the old-fashioned approach and use a ScriptManager then.
    • iJade
      iJade over 10 years
      try adding a error callback and do a console log of the error
    • JWiley
      JWiley almost 9 years
      As embarrassing as it is to admit this, my problem was because the method's access modifier was private instead of public....
    • Daniel Sh.
      Daniel Sh. almost 9 years
      @JWiley it's great once you've found out though. :)
    • Artemix
      Artemix over 7 years
      What was the problem in .aspx page? (In your accepted answer). I'm the 11th person that upvotes the comment under your answer, but no one replied yet.
    • Daniel Sh.
      Daniel Sh. over 7 years
      @Artemix for some reason I thought I replied in the past. It's done now, and I'm also updating the answer. Thanks
  • Daniel Sh.
    Daniel Sh. about 10 years
    glad it helped @Rahul :)
  • InGeek
    InGeek about 10 years
    wahahhahhah thanks sooooooooooooooooooooooooooooo much. exactly silly spent 3 hours on it
  • Daniel Sh.
    Daniel Sh. about 10 years
    @INgeeg glad I was of help :)
  • LacOniC
    LacOniC over 8 years
    What was the problem in .aspx page?
  • Mohammed Dawood Ansari
    Mohammed Dawood Ansari over 8 years
    I got the same issue while using WebMethod in ASP .NET Page, just made it static and it started working. +1
  • msulis
    msulis over 7 years
    thanks for admitting it here for those of us who were suffering the same sad situation!
  • Daniel Sh.
    Daniel Sh. over 7 years
    @LacOniC the line <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xxx.xxx.cs" Inherits="xxx.xxx" %> was mistakenly erased from the page. Added it and it worked.
  • GoldBishop
    GoldBishop over 6 years
    converted a page member method to a webmethod and forgot to change scope and member attribute....
  • Protector one
    Protector one over 5 years
    Yes, very tired. Same goes for protected methods.
  • John Baker
    John Baker over 5 years
    I've done this a hundred times, and I always forget the attribute. Thanks!
  • NickG
    NickG over 5 years
    The second part of this worked for me. It was some kind of stupid caching issue. Rename the function by adding "2" to the end (client-side and server side) and it worked! Renamed it back to the original name: STILL working, despite the code now being byte-identical to when it didn't work. And I'd already cleaned out Temporary ASP.NET Files so god knows where it was being cached... (RAM?)
  • Lukas
    Lukas almost 4 years
    I can't believe that worked! In my asmx page I had a public static method. After removing the static the method was hit successfully! Thank you!