Sometimes I am getting a time out exception when reading an XML via a URL. Is there something I can do to prevent this, or is this a problem with the remote server? Below is
I had this problem earlier and found this unanswered question. An option I have found is to prevent the request from timing out at all, which you can do creating your own WebRequest with a timeout of Timeout.Infinite and passing it into the XmlReader.
WebRequest request = WebRequest.Create(this.RssUrl);
request.Timeout = Timeout.Infinite;
using (WebResponse response = request.GetResponse())
using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
{
// Blah blah...
}
You can also set the KeepAlive if you use a HttpWebRequest, although it is actually true by default, so it should not make any difference.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.RssUrl);
request.KeepAlive = true;