My asp.net application sends httpwebrequest to the remote REST server and waits for a response, and I found that there are many identical error messages like this:
System.Net.WebException: The operation has timed out. in System.Net.HttpWebRequest.GetResponse ()
Is it possible that after I catch this exception and close the basic http connection right away? or do I really not need to do this since I already set keepalive to false?
Thanks.
Actually one more question: if the timeout exception has always been in System.Net.HttpWebRequest.GetResponse(), does this mean that the application is waiting for a response from the remote server and cannot receive the response before the timeout expires. what could be the possible reason, the network connection is unstable? the remote server is not responding? any other possible reasons?
Here is the code:
System.Net.HttpWebResponse httpWebResponse = null; System.IO.Stream stream = null; XmlTextReader xmlTextReader = null; try { System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(request); httpWebRequest.ReadWriteTimeout = 10000; httpWebRequest.Timeout = 10000; httpWebRequest.KeepAlive = false; httpWebRequest.Method = "GET"; httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse(); stream = httpWebResponse.GetResponseStream(); xmlTextReader = new XmlTextReader(stream); xmlTextReader.Read(); xmlDocument.Load(xmlTextReader); //Document processing code. //... } catch { //Catch blcok with error handle } finally { if (xmlTextReader != null) xmlTextReader.Close(); if (httpWebResponse != null) httpWebResponse.Close(); if (stream != null) stream.Close(); }
machinegone
source share