Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX WebService in ASP.Net - how to global error handling? [duplicate]

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?

like image 510
PassionateDeveloper Avatar asked Nov 01 '22 06:11

PassionateDeveloper


1 Answers

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

like image 145
Shajo Avatar answered Jan 04 '23 14:01

Shajo