Monday, March 26, 2012

Intercept Exceptions

I was wanting to trap Exceptions that occur in a Web Service, adjust the message (make sure stack trace does not get sent (I know about CustomErrors in web.config)) and put the message in a log.

I found out about SoapExtensions and created such, but just was not able to reach any breakpoints. I then read that I wouldn't reach it unless through a Soap request. So I used WebServiceStudio.exe and hit those breakpoints.

Well, when using Atlas, the full exception was being sent without running through the SoapExtension. I assume now that xmlhttp uses Post requests. Then in web.config WebServices node, I cleared the protocols and added only the Soap protocols... interesting thing is Atlas still called the web service and got the thrown error returned. That made me think it used Soap, but it still never hit the SoapExtension.

Could somebody clear up this confusion? I assume there must be a way to globally intercept Web Service errors. For Web Applications, I use global.asax Application_Error.

Nathan

Atlas does not use SOAP. It uses REST and the serialization method is JSON. Atlas has a custom HTTP Handler for .asmx files, which you can see in your wen.config file. When an Atlas script requests a web service, a special query string parameter named "mn" is appended to the url. The server side web service checks the presense of this parameter and and if it is present it uses custom processing bu Atlas otherwise it uses the default web service handler.The normal processing, which you expect when you call a web service like soap extension execution etc. no longer happens because of the Atlas custom handler. The Atlas custom handler directly catches the excpetion from the web service method and reports to the client, when the web service is invoked from an Atlas script. There is only one option currently (may change in future) and that is to handle the exceptions in the web service methods themshelves. I do not think that there is any global exception hooking mechanism you can use for Atlas.

No comments:

Post a Comment