如果我使用的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.