s.k.Soni s.k.Soni - 3 years ago 211
Ajax Question

Server Error in '/' Application. Unknown web method. Parameter name: methodName in web services

I am using web services in asp.net with c#. In that I am working in one task that is to call the method from ajax in web services. But whenever I call the method from ajax in button click event at that time it shows the error i.e. 500 (internal server error) and when I am go the network in developer tools it shows me Unknown web method and method. Parameter name : methodname.

Here is the ajax function code

$("#submit").click(function () {
$.ajax({
type: "POST",
url: "OakscrollWebService.asmx/SendMail",
dataType: "json",
data: JSON.stringify({ name: $('#name').val(), email: $('#mail').val(), subject: $('#subject').val(), message: $('#message').val() }),
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data.d);
},
failure: function (data) {
alert("something went wrong");
//console.log(msg);
}
});
});


and here is the cs code

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public static void SendMail(string name, string email, string subject, string message)
{
}


I have noticed one more thing that is sendmail method is not showing in asmx file when I am run that file. Surprised that why it is not coming.

Please help to solve this issue.

Thanks.

Answer Source

In .asmx file, your method should not be static if you want to use it across several pages:

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public void SendMail(string name, string email, string subject, string message)
{
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download