Thursday, July 17, 2008

ASP.NET 2.0 Web Request Timeout - Configuring Long Running Web Request

In ASP.NET both a Web request (ASPX) pages together with Web Service Pages (ASMX) constitute a web request.

All web requests have a request timeout.

The ASP.NET script timeout (Request Timeout) also depends on the compilation node set in web.config.

When debug set to true

<compilation debug="true" />


The value for request timeout is 30,000,000 seconds (close to a year 31,536,000 Seconds)

This value is internal and can be found on the page init using


private int timeout = 0;


protected void Page_Init(object sender, EventArgs e)

{

timeout = Server.ScriptTimeout;

}

protected void Page_Load(object sender, EventArgs e)

{

Response.Write("Timeout:" + timeout);

}

When debug set to false

<compilation debug="false" />

The value for request timeout is 110 seconds

This value is config setting and can be found in machine level web.config (web.config.comments) under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG

<httpRuntime
executionTimeout = "110" [in Seconds][number]



With regard to the production environment the value should always be
<compilation debug="false" />

With regard to long running web request I have addressed these three scenarios

1. Long running Web Request Call
2. Web Request Call which in turn calls a long running Web Service Synchronously
3. Web Request Call which in turn calls a long running Web Service Asynchronously


Scenario:1 Long running Web Request Call
In order to make a longer web request call you need to override the <httpRuntime node and set the executionTimeout to a higher value depending on your need.

<httpRuntime
executionTimeout = "180" [in Seconds][number]


Setting present under system.web on the Web.config of the current application.

Scenario:2. Web Request Call which in turn calls a long running Web Service Synchronously
Since there are two applications involved here (one Web Application and the other Web Service Application) you need to increase the executionTimeout in both the applications web.config to a value equal to the longest time taken between them.


<httpRuntime
executionTimeout = "240" [in Seconds][number]


Now that we have increased the request time we now have to tell the web request page to increase the webproxy call time from the default 100 Seconds.

This is specified in the proxy created for the webservice


CalculatorService.CalculatorWS calculator;
calculator = new WebPlayground2005.CalculatorService.CalculatorWS();
calculator.Timeout = 190000 //milliseconds;


Scenario:3. Web Request Call which in turn calls a long running Web Service Asynchronously
Fortunately this is easier and require only the web.config of the web services application having an overide setting for

<httpRuntime
executionTimeout = "190" [in Seconds][number]


ASP.NET is clever enough to increase the web application request timeout till the asynchronous call is returned from the web service.

Happy Programming,
Anton

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home