Pages

Thursday, August 30, 2012

Fix for 401 errors when getting data via C# webservice for AJAX

Application wide:
In your web.config, add the following lines.
<system.web>
  <webServices>
    <protocols>
      <add name="HttpGet" />
      <add name="HttpPost" />
    </protocols>
  </webServices>
</system.web>

Code level:
Add the following before your webservice method.
[ScriptMethod(UseHttpGet = true)]

Example:
[ScriptMethod(UseHttpGet = true)]
[WebMethod(Description = "webservice description.")]
public List GetItems()
{
  // more codes
}