What is a reasonable amount of time to wait for a web request to return? I know this is maybe a little loaded as a question, but all I am trying to do is verify if a web page is available.
Maybe there is a better way?
try { // Create the web request HttpWebRequest request = WebRequest.Create(this.getUri()) as HttpWebRequest; request.Credentials = System.Net.CredentialCache.DefaultCredentials; // 2 minutes for timeout request.Timeout = 120 * 1000; if (request != null) { // Get response response = request.GetResponse() as HttpWebResponse; connectedToUrl = processResponseCode(response); } else { logger.Fatal(getFatalMessage()); string error = string.Empty; } } catch (WebException we) { ... } catch (Exception e) { ... }
You need to consider how long the consumer of the web service is going to take e.g. if you are connecting to a DB web server and you run a lengthy query, you need to make the web service timeout longer then the time the query will take. Otherwise, the web service will (erroneously) time out.
I also use something like (consumer time) + 10 seconds.