相关疑难解决方法(0)

使用XmlReader.Create(uri)防止或处理超时

有时我通过URL读取XML时会遇到超时异常.有什么我可以做的,以防止这种情况,或者这是远程服务器的问题?下面是我的简单代码:

XmlDocument doc = new XmlDocument();
doc.Load(XmlReader.Create(this.RssUrl));
Run Code Online (Sandbox Code Playgroud)

我发现一篇文章说KeepAlive可能有所帮助,但我不知道如何将该设置传递到上面的代码中(或者如果这是正确的解决方案):http://www.velocityreviews.com/forums/t95843-系统引发WebException最操作具有定时,out.html

这是例外,请帮忙!

Exception Details: System.Net.WebException: The operation has timed out
Stack Trace: 

[WebException: The operation has timed out]
   System.Net.HttpWebRequest.GetResponse() +5375213
   System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) +69
   System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +3929371
   System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +54
   System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext) +144
   System.Xml.XmlReader.Create(String inputUri) +8
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net xmlhttprequest .net-3.5

4
推荐指数
1
解决办法
4456
查看次数

标签 统计

.net ×1

.net-3.5 ×1

asp.net ×1

c# ×1

xmlhttprequest ×1