Web Client takes too long time to recognise a network failure RRS feed

  • Question

  • Hello everyone,

    In my WPF application, I using Web client for downloading and uploading files. I overrided WebClient's GetWebRequest() method as below

      protected override WebRequest GetWebRequest(Uri address)
                var objWebRequest = base.GetWebRequest(address);          
                objWebRequest.Timeout = 2100000;
                return objWebRequest;

    When I disconnect network during any file upload or download. It throws WebExcpetion and identifies network failure only after long time.

    In the above method when I reduce the Timeout of HttpWebRequest, it identifies network failure faster than before, but fails to upload large files through web service. In this scenario, I am getting exception as Request was aborted, Request was cancelled.

    I tried overriding HttpWebRequest(objWebRequest).KeepAlive = false;

    But didn't work. 

    Please suggest me ways to recognize network failure state immediately when connecting through web client.

    Monday, March 23, 2015 11:06 AM


  • What you want to do is reduce the timeout to be responsive.  The issue that I can see is the term "large files."

    If you're attempting to send or receive large files, you really have to start to use some of the features of the headers such as the Range header, making repeated calls to get the entire file.   Each HTTP request will perform within the timeout, and the program will be responsive during the download.

    You get piece by piece and then re-assemble the data.

    If you have a timeout of 210,000 ms, like in the above code, you're definitely in the area of requiring the range header.  210 seconds is insanely large for a timeout.

    Darin R.

    • Proposed as answer by Fred Bao Tuesday, March 24, 2015 2:56 AM
    • Marked as answer by Fred Bao Tuesday, April 7, 2015 8:12 AM
    Tuesday, March 24, 2015 12:04 AM