ASP.NET ASMX service occasionally throws exceptions. However, global.asax Application_Error method do not seem to catch them. The question is, how to configure global error handler to catch and log these exceptions?
3 回答
ASMX Web 服务的基本问题(这不是问题)是服务层后面的任何异常都会作为 SOAP 异常抛出给客户端。您需要捕获 SOAP 异常,然后在那里寻找内部异常。
更好更干净的方法是在应用程序中实现 SOAP 处理程序。通过此序列化 SOAP 异常并在客户端反序列化它。这样,您将完全控制异常流,而不是 .net 框架。
高温高压
Is it the ASMX or the AJAX JavaScript which is throwing the exception?
If it's the Javascript, you'll need to write exception handling into your JS, and then push that back to the server to be tracked in your error datastore--possibly via another call to your webservice.
If it's the ASMX then it's probably getting caught by your Application_Error, BUT as ASMX returns XML or JSON it won't necessarily get displayed on your UI unless you're looking for it.
Client-side I Would simply wrap your call to the service in a JavaScript. On the server-side the error should be logged in your server log as an. http 500 error