Javascript - Calling Asp.net Webservice - The Server Method 'methodname' Failed
Solution 1:
If you are not using .NET 4 then you need to do configuration entries to enable script service. See http://msdn.microsoft.com/en-us/library/bb398998(v=VS.90).aspx. So make sure that you have following section in web.config.
<system.web>
...
<httpHandlers><removeverb="*"path="*.asmx"/><addverb="*"path="*.asmx"type="System.Web.Script.Services.ScriptHandlerFactory"validate="false"/></httpHandlers>
...
<system.web>
For trouble-shooting, you can look at the stack trace of the exception - for example,
function OnError(result) {
alert("Error: " + result.get_message());
alert("Stack Trace: " + result.get_stackTrace());
}
Solution 2:
Try applying [ScriptMethod] attribute on the PieTable method, this usually solves my problems when calling webmethods with JQuery.
http://msdn.microsoft.com/en-us/library/system.web.script.services.scriptmethodattribute.aspx
[WebMethod]
[ScriptMethod]
publicstringPieTable(string table)
{
return table + " - resultant text";
}
Solution 3:
I have found in the past that putting () after ScriptService in the attribute declared on the web service class has seemingly solved certain bizarre problems. No idea why it might have worked but worth a try in your case too.
i.e.
[WebService(Namespace = "http://localhost:2900/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
publicclassWebServices1 : WebService
{
[WebMethod]
publicstringPieTable(string table)
{
return table + " - resultant text";
}
}
Post a Comment for "Javascript - Calling Asp.net Webservice - The Server Method 'methodname' Failed"