如果我使用的Web服务超时,会抛出什么异常? [英] What exception is thrown if a web service I'm using times out?

查看:115
本文介绍了如果我使用的Web服务超时,会抛出什么异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在现有的.NET 2.0 Web服务中调用.NET 2.0 Web服务。我想知道如果超时发生从Web方法抛出什么异常。我已将Web服务超时设置为比默认90秒更低的值,并且如果发生超时,我想添加业务逻辑。

I'm calling a .NET 2.0 web service within my existing .NET 2.0 web service. I would like to know what exception is thrown from the web method if a timeout happens. I have set the web service timeout to some lower value than the default 90 seconds and I want to add business logic if timeout happens.

[ System.Net.WebException] [1] 我应该查看的异常?

推荐答案

使用WCF,您实际上会得到一个 TimeoutException 。如果您尝试处理 CommunicationException ,通常也应该处理超时。有时我也见过 FaultException ,尽管不应该发生(但偶尔也会发生)。 FaultException CommunicationException 的后代,因此您无需单独处理它,知道它很有用

Using WCF, you will actually get a TimeoutException. You should generally also handle CommunicationException if you are attempting to handle timeouts. Sometimes I've also seen FaultException, although that technically shouldn't happen (but it does anyway once in a while). FaultException is a descendant of CommunicationException so you don't need to handle it separately, it's just useful to know that it might occur.

在ASMX中,通常会得到一个包装好的 SoapException ,您需要检查其 InnerException 属性以查看真正出了什么问题。

In ASMX, you will usually get a wrapped SoapException for which you need to check the InnerException property to see what really went wrong.

使用WSE,您还会看到另一个例外, ResponseProcessingException ,对此您必须再次检查 InnerException 以获得详细信息。

Using WSE, you'll see yet another exception, ResponseProcessingException, for which again you must check the InnerException for details.

这篇关于如果我使用的Web服务超时,会抛出什么异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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