Unknown web method. Parameter name: methodName
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.
![Daniel Sh.](https://i.stack.imgur.com/xlTSN.jpg?s=256&g=1)
Comments
-
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 over 10 years
static
web methods are not supported. -
Daniel Sh. over 10 yearsmaybe 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 over 10 yearsAh ok, are you using a ScriptManager? If so do you have the EnableScriptMethods enabled?
-
Daniel Sh. over 10 yearsNo, just using jQuery, I was sure there's no need to use a ScriptManager
-
James over 10 yearsno you shouldn't have to, I am just trying to gauge your setup. Which page are you running the JS from?
-
Daniel Sh. over 10 yearsAnd 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 over 10 yearsNo worries, have you tried passing an empty
data
param? i.e.data: "{}"
? -
Daniel Sh. over 10 yearsthat 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 over 10 yearsCode 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. over 10 yearsSame, don't know what else to try :/
-
James over 10 yearsHmm my initial incling was the URL was wrong, could you try something like
url: window.location.href + "/HelloWorld"
? -
Daniel Sh. over 10 yearsSame :/ it's not being accesed at all.
-
James over 10 yearsI'd opt for going for the old-fashioned approach and use a ScriptManager then.
-
iJade over 10 yearstry adding a error callback and do a console log of the error
-
JWiley almost 9 yearsAs embarrassing as it is to admit this, my problem was because the method's access modifier was private instead of public....
-
Daniel Sh. almost 9 years@JWiley it's great once you've found out though. :)
-
Artemix over 7 yearsWhat 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. 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. about 10 yearsglad it helped @Rahul :)
-
InGeek about 10 yearswahahhahhah thanks sooooooooooooooooooooooooooooo much. exactly silly spent 3 hours on it
-
Daniel Sh. about 10 years@INgeeg glad I was of help :)
-
LacOniC over 8 yearsWhat was the problem in .aspx page?
-
Mohammed Dawood Ansari over 8 yearsI got the same issue while using WebMethod in ASP .NET Page, just made it static and it started working. +1
-
msulis over 7 yearsthanks for admitting it here for those of us who were suffering the same sad situation!
-
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 over 6 yearsconverted a page member method to a webmethod and forgot to change scope and member attribute....
-
Protector one over 5 yearsYes, very tired. Same goes for
protected
methods. -
John Baker over 5 yearsI've done this a hundred times, and I always forget the attribute. Thanks!
-
NickG over 5 yearsThe 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 almost 4 yearsI 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!