5

I have around 50+ AJAX WebMethods in my *.aspx site, which is called by JQuery (sometimes raw jquery, sometimes over lib's).

Here are a few examples:

 [WebMethod]
    public static string GetLog()
    {
        DAL.LogService log = new DAL.LogService();
        string items = log.GetLog();
        return items;
    }

    [WebMethod]
    public static void ClearBenchmarks()
    {
        DAL.LogService log = new DAL.LogService();
        log.ClearBenchmarks();
    }

    [WebMethod]
    public static void WriteLog(string message1, string message2, string user, string type)
    {
        DAL.LogService.WriteLog(message1, message2, user, type);
    }

In fact in the most time, they only redirect to the dataLayer of my application, but in fact, ofc, I have 50+ single methods...

Now I want to include error handling in my application - how to do that globaly without having try catch in every single method?

PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176

1 Answers1

2

This is a known issue in .Net - Application_Error of global.asax never fires for a web service.

so you could try following ideas.

  1. you could place a try-catch around each web service method

  2. Use a facade design pattern and include the try-catch in parent objects

  3. Write a custom SOAP extension or HTTPModule

Hope this helps

Shajo
  • 873
  • 2
  • 11
  • 22