What exception is thrown if the web service I use is disconnected?

I am calling the .NET 2.0 web service as part of an existing .NET 2.0 web service. I would like to know which exception is thrown from the web method if a timeout occurs. I set the web service timeout to less than 90 seconds by default, and I want to add business logic if the timeout occurs.

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

+4
source share
2 answers

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

Using WCF, you really get a TimeoutException . You should also handle CommunicationException if you are trying to handle timeouts. Sometimes I also saw a FaultException , although technically this should not happen (but it is still from time to time). FaultException is a descendant of CommunicationException , so you do not need to handle it separately, it is just useful to know that this can happen.

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

Using WSE, you will see another exception, ResponseProcessingException , for which again you should check InnerException for details.

+7
source

You should look for a TimeoutException :

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

+1
source

Source: https://habr.com/ru/post/1304468/


All Articles