使用 2.0 样式和 WCF 代理进行正确的错误处理
Microsoft 提供的有关此问题的信息数量惊人地少,或者我对该问题的了解不够,无法找到文档。
当使用传统的 VS2005 和 .NET 2.0 Web 服务代理使用 Web 服务时,除了故障异常之外,还可以抛出哪种类型的通信异常以及通过哪些程序集/命名空间。
我很难从 System.ServiceModel 中找到与 WCF 的 ServiceActivationException 和 CommunicationException 等效的内容 - 这些是相同的异常吗?
Microsoft has provided surprisingly small amounts of information regarding this issue or I do not know enough about the problem to locate the documentation.
When consuming web services using the traditional VS2005 and .NET 2.0 web service proxies, aside from FaultExceptions, what sort of communication exceptions can be thrown and through which assemblies/namespaces.
I am having difficulty locating the equivilent to WCF's ServiceActivationException and CommunicationException from System.ServiceModel - are these the same exceptions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几乎所有与 WCF 相关的异常都源自 CommunicationException,因此如果您查阅 MSDN 文档中的后代类列表,您应该会有所了解。
例外是通用的 TimeOutException(来自 System.Net 命名空间)和 QuotaExceeded 来自
System.ServiceModel
命名空间的异常,令人惊讶的是,它并非源自CommunicationException
- 为什么是这样的,我不知道。Pretty much all WCF related exceptions descend from CommunicationException so if you consult the list of descendant classes in the MSDN documentation, you should be covered.
Exceptions are the generic
TimeOutException
(from theSystem.Net
namespace) and the QuotaExceeded exception from theSystem.ServiceModel
namespace which surprisingly does not descend fromCommunicationException
- why that is the case, I don't know.ASMX 代理可以抛出
SoapException
或HttpWebRequest
可以抛出的任何异常。然而,你必须问自己:你为什么关心?对于一种异常类型和另一种异常类型,您将采取哪些不同的做法?您实际上可以处理任何这些异常吗,或者您只是记录它们并让它们传播(我希望您不会捕获它们然后忽略它们)。
An ASMX proxy can throw
SoapException
, or anything that can be thrown byHttpWebRequest
.However, you have to ask yourself: why do you care? What are you going to do differently between one exception type and another? Can you actually handle any of these exceptions, or will you simply log them and let them propagate (I hope you're not going to catch them and then ignore them).