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?
This is a known issue in .Net - Application_Error of global.asax never fires for a web service.
so you could try following ideas.
you could place a try-catch around each web service method
Use a facade design pattern and include the try-catch in parent objects
Write a custom SOAP extension or HTTPModule
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With