global.asax Application_Error method does not catch exceptions thrown by ASMX service?
2011-07-22 15:32
344 查看
This is a known issue in .Net - Application_Error never fires for a web service. Not sure if there's any reason it would be by design, but it just doesn't work.
Jeff Atwood had a post about this a few years ago, with the following ideas:
Put a try-catch block 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
The only one I care for is the first one, even though it seems like a lot of work.
Better: HttpApplication.Error event:
For anyone looking for Microsoft's word on this topic, see here: "Handling and Throwing Exceptions in XML Web Services".
This is the relevant section:
A Web application can be comprised of multiple XML Web services, however the Application_Error event within the Global.asax file cannot be used for global exception handling. The HttpHandler for XML Web services consumes any exception that occurs while an XML Web service is executing and turns it into a SOAP fault prior to the Application_Error event is called.
Jeff Atwood had a post about this a few years ago, with the following ideas:
Put a try-catch block 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
The only one I care for is the first one, even though it seems like a lot of work.
Better: HttpApplication.Error event:
Note:
If your Web application contains XML Web services, you cannot use the Error event for global exception handling of those services. The HTTP handler for XML Web services consumes any exception that occurs in an XML Web service and converts it to a SOAP fault before the Error being called. To handle XML Web service exceptions, build a SOAP extension to process Web service exceptions in a custom global exception handler. For more information, see Handling and Throwing Exceptions in XML Web Services.For anyone looking for Microsoft's word on this topic, see here: "Handling and Throwing Exceptions in XML Web Services".
This is the relevant section:
A Web application can be comprised of multiple XML Web services, however the Application_Error event within the Global.asax file cannot be used for global exception handling. The HttpHandler for XML Web services consumes any exception that occurs while an XML Web service is executing and turns it into a SOAP fault prior to the Application_Error event is called.
相关文章推荐
- The ServiceClass object does not implement the required method in the following form: OMElement...
- Global.asax的Application_Error实现错误记录/错误日志的代码
- Global.asax 文件之 Application_Error
- Caused by: org.postgresql.util.PSQLException: ERROR: relation "item" does not exist
- android用gdb调试时遇到报错: ERROR: The device does not support the application's targetted CPU ABIs!
- “Parser Error Message: Could not load type” in Global.asax
- Solve VS2010 Error "Exceptions has been thrown by the target of an invocation"
- does not contain handler parameter named 'method'. This may be caused by whit
- Global.asax中的Application_Error事件不执行
- 无法启动soapUI3.0.1 Error: the jvm could not be started. the main method may have thrown an exception
- ASP.NET MVC中注册Global.asax的Application_Error事件处理全局异常
- The ServiceClass object does not implement the required method in the following form: OMElement sayH
- Global.asax的Application_Error实现错误记录/错误日志的代码
- 解决AS导入Error:(1, 0) Could not find method apply() for arguments [{plugin=com.android.application}]错误
- ASP.NET MVC中注册Global.asax的Application_Error事件处理全局异常
- 解决和说明> eth.getCompilers() Error: The method eth_getCompilers does not exist/is not available
- ASP.NET利用Global.asax的Application_Error来记录Exception信息
- org.apache.axis2.AxisFault: The ServiceClass object does not implement the required method in the following form: OMElement get
- ERROR - ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
- Resolve Error: The service cannot be activated because it does not support ASP.NET compatibility.