0

我试图在 IsTransient 方法中捕获具有特定状态的WebException,但它从未捕获以下错误:

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

这是代码:

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;
    }

当我通过断开扫描仪设备上的互联网连接来测试它时,它返回 true,但在生产环境中,当 Web 服务调用超时时它不起作用。

4

0 回答 0