5

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.

Is [System.Net.WebException][1] the exception I should be looking at?

BT.
  • 505
  • 3
  • 8
  • 16

2 Answers2

9

This kind of depends on which "version" of web services you are using.

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.

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

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

Aaronaught
  • 120,909
  • 25
  • 266
  • 342
  • I'm using .NET 2.0 web services – BT. Mar 18 '10 at 15:50
  • @BT: *.NET 2.0* isn't a type of web service, it's a Framework version. Assuming you mean ASMX web services, see the third paragraph. – Aaronaught Mar 18 '10 at 16:09
  • Thanks! i assume that the InnerException is also a type of exceptio, so my question remains there that how i'm going to know that it's timeout exception, i mean what type of inner exception i should be looking at? – BT. Mar 18 '10 at 16:35
  • 1
    @BT: Judging by some of the (very old) bug reports in our database, the `InnerException` is likely to be an `HttpException` with `HttpStatusCode.RequestTimeout` (HTTP 408). Although there may have been other kinds of timeouts that went unreported. – Aaronaught Mar 18 '10 at 16:48
1

You should be looking for a TimeoutException:

The exception that is thrown when the time allotted for a process or operation has expired.

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
  • 2
    It does not work in case of web service. Catching [WebException](http://msdn.microsoft.com/en-us/library/system.net.webexception(v=vs.110).aspx) will do. – broadband Jan 10 '14 at 09:01