NerdyHearn
Home
Blog
Software

Contact
Mailing List

IPhone Products
SMS To Gmail
Voicemail To Gmail
Calls To Calendar

Other Products
TiffWizard

Sites
SaveMySerials
How Long For Me
DocuTerminal

Blog
Twitter

NerdyHearn - Blog


<< Back To All Blogs

Resolving Odd 5 Minute Timeout in HttpWebRequest.

Monday, December 7th, 2009

Recently I have been using the HttpWebRequest class a large amount, and we came across a scenario in which I was continually getting a timeout, but I had been setting the Timeout property of the HttpWebRequest to much larger than 5 minutes, but was still receiving the timeout.

In this case we were using an synchronous call through a StreamReader to get back all of the data as simple text:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = reader.ReadToEnd();

It was timing out on reader.ReadToEnd() which made me suspicious of a possible stream timeout, and after some digging that was indeed the case.

The stream reading abilities of HttpWebRequest will by default timeout at 5 minutes (300 seconds), and in order to get around this issue you need to set the ReadWriteTimeout property, such as follows:

request.ReadWriteTimeout = 600; // In seconds, so this would be 10 minutes

This will not apply to asynchronous requests, just as a note of interest.

A rather simple issue, but was very frustrating at first as we were trying to simply increase the Timeout property.

Timeoutin' Tom Out.

Tags

ASP.NET Howto

Related Blogs

Impersonating a user in ASP.NET
Resolving ASP.NET Web.Config Inheritance
Configuring ASP.NET (And SharePoint) to use SQL-based Sessions
Validate a Windows Username and Password against Active Directory
Disabling Outlook restricted extensions

Comments

Currently no comments.

Add A Comment

Name:


URL:


Email Address: (not public, used to send notifications on further comments)


Comments:



Enter the text above, except for the 1st and last character:


NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers SubSonos - Stream your subsonic music collection to your Sonos wireless system