0

Getting a webrequest timeout when trying to download large video files through WebDAM's (a third party content management system) API. Here is the basic code that is used to get the video.

public void StreamAsset(String AssetID, HttpResponse Response)
    {

            WebRequest request = request = WebRequest.Create(_api_url_v2 + "assets/" + AssetID + "/download");
            request.Timeout = 200000;
            // add OAuth header
            request.Headers.Add("Authorization", "Bearer " + _access_token);

            // get response from WebDAM web service
            WebResponse response = request.GetResponse();
            using (Stream file = response.GetResponseStream())
            {
                Int32 bytesRead = 0;
                Byte[] buffer = new Byte[524000];

                while ((bytesRead = file.Read(buffer, 0, buffer.Length)) > 0)
                {
                    if (Response.IsClientConnected)
                        Response.OutputStream.Write(buffer, 0, bytesRead);
                    else
                        break;
                }
                file.Close();
            }

        }


    }

Is there a more efficient way to write this code or do I just have to jack up the timeout property.

I get the pretty standard following error.

Stack Trace: [HttpException (0x80004005): Request timed out.]

ekim110575
  • 37
  • 4

1 Answers1

0

Try adding the httpRuntime timeout in your Web.config file like below...

<system.web>
    <httpRuntime executionTimeout="n"/>
</system.web>

...where n is the number of seconds that your request is allowed to execute before being automatically shut down by ASP.NET.

Scotty
  • 1,127
  • 1
  • 7
  • 17