处理全局错误 [英] handle global errors asmx

查看:92
本文介绍了处理全局错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有实现asmx服务的类.

I have class that implements asmx service.

class AsmxService{
public string Method(int i){.....}
....}

我省略了一些属性,但是如果需要的话可以提供完整的代码.

I omit some attributes, but can provide full code if you find it necessary.

如果我在Method方法中遇到异常,那不是问题:只需使用try-catch即可.但是,如果函数外部发生错误,我们该怎么办.例如,客户端传递了无效的int参数或其他参数.在这种情况下,我会在客户端收到有关异常的消息.但是我想隐藏所有错误细节,并总是返回简单的通知,如下所示:发生错误.无法处理请求."

If I get exception into function Method, it's not a problem: just use try-catch. But what should we do, if error occured outside the function. For example, client passed invalid int parameter or something else. In that case on client side I get message about exception. But I d'like to hide all details of error and always return simple notification like following one: "An error occured. Impossible to process request".

我试图编写SOAP扩展模块,但发现它没有捕获与asmx相关的异常.

I attempted to write SOAP extension module but I found that it did not catch exception related with asmx.

那有可能吗?如果答案是是",那我应该怎么做?

So is it possible at all, and if answer is 'yes', what I am supposed to do?

似乎这个问题不时出现在stackaverflow上,但是我找不到决定.

It seems that this problem rised from time to time on stackaverflow, but I wasn't able to find decision.

推荐答案

对于由Web服务基础结构发送回的故障,您无能为力.如果您使用的是WCF,则可以完全控制,但是使用ASMX则无能为力.

There isn't anything you can do about faults sent back by the web service infrastructure. If you were using WCF, you would have pretty much complete control, but there's nothing you can do about it using ASMX.

这篇关于处理全局错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆