I'm trying to catch WebException with certain Status inside IsTransient method, but it never catches the following error:
System.Net.WebException: Unable to read data from the transport connection: Connection timed out. ---> System.IO.IOException: Unable to read data from the transport connection: Connection timed out. ---> System.Net.Sockets.SocketException: Connection timed out
And here's the code:
private bool IsTransient(Exception ex)
{
var webException = ex as WebException;
if (webException != null)
{
return new[]
{
WebExceptionStatus.ConnectionClosed,
WebExceptionStatus.ConnectFailure,
WebExceptionStatus.Timeout,
WebExceptionStatus.RequestCanceled,
WebExceptionStatus.ReceiveFailure
}.Contains(webException.Status);
}
return false;
}
When I test it by disconnecting the internet connection on scanner device it returns true, but in production environment when web service calls timeout it's not working.