Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown web method. Parameter name: methodName

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?

like image 307
Daniel Sh. Avatar asked Dec 22 '13 23:12

Daniel Sh.


4 Answers

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.

like image 162
Rob Church Avatar answered Nov 19 '22 21:11

Rob Church


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 :(.

like image 25
Daniel Sh. Avatar answered Nov 19 '22 20:11

Daniel Sh.


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.

like image 3
ΩmegaMan Avatar answered Nov 19 '22 22:11

ΩmegaMan


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

like image 3
hogarth45 Avatar answered Nov 19 '22 22:11

hogarth45