Skip to content Skip to sidebar Skip to footer

Javascript - Calling ASP.NET WebService - The Server Method 'methodName' Failed

I've been trying to resolve this issue for a while and haven't been successful yet. I've got a basic ASP.NET WebService which I'm trying to call from javascript as such. using Syst

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>
    <remove verb="*" path="*.asmx"/> 
    <add verb="*" 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]
public string PieTable(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()]
public class WebServices1 : WebService
{
    [WebMethod]
    public string PieTable(string table)
    {
        return table + " - resultant text";
    }
}

Post a Comment for "Javascript - Calling ASP.NET WebService - The Server Method 'methodName' Failed"