0

I am getting the following error while I am reading an remote xml file to convert currency on HttpWebRequest.GetResponse() section.

the method that I used TugberkUgurlu_CurConverter.ConverterClass.ConvertActionForTL() is reading an xml file and get a currency value.

but suddenly, I started getting these errors. how can I prevent them? thanks !

System.Net.WebException: The operation has timed out Generated: Mon, 28 Mar 2011 19:33:48 GMT

System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) at System.Threading.CompressedStack.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) at System.Xml.XmlTextReaderImpl.OpenUrl() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at TugberkUgurlu_CurConverter.ConverterClass.ConvertActionForTL(CurrencyForTLConvert SelectCurrency, Decimal YourPriceToConvert)

John Saunders
  • 160,644
  • 26
  • 247
  • 397
tugberk
  • 57,477
  • 67
  • 243
  • 335
  • Please show the XML you're trying to load. I believe the stack trace is telling you that the XML includes a reference to an entity which it is attempting to resolve to an external URL - a URL which is not responding. – John Saunders Mar 28 '11 at 20:03
  • @John thanks for the reply. here is the url. http://www.tcmb.gov.tr/kurlar/today.xml I am in Turkey now and I can view the file. but the exception was thrown by the request in the UK two times today. – tugberk Mar 28 '11 at 20:07

1 Answers1

1

I don't see any problems with the file you linked, and neither does XMLSpy.

You say it's a problem occasionally, and the file contains currency conversion values, which are likely to change frequently. Perhaps the file is occasionally bad?

Perhaps you should try loading the file as a text file first, and save it to disk. Then load the XmlDocument from the file on disk. That way, if it fails, you've still got the bad file to look at.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • that's a very good idea. but is there any sample that shows how to load the file as a text file first, and save it to disk. Or can you give a heads-up here? – tugberk Mar 28 '11 at 20:18
  • I have managed to log the error and the user which faced the error. I have told the customer that the problem was momentary and to try again. the stack trace I have given is the second time error. So I can't tell to try again :) – tugberk Mar 28 '11 at 20:20
  • Use [WebClient.DownloadFile](http://msdn.microsoft.com/en-us/library/ms144194.aspx) – John Saunders Mar 28 '11 at 20:20
  • thanks. I will give it a try. is there any chance that I can save it to the cache and use it from there. I do not wanna save it to the disk – tugberk Mar 28 '11 at 20:24
  • You can, but I'm thinking of this as a debugging mechanism. Hopefully, once you find out what the problem is, you'll fix it and won't need this. – John Saunders Mar 28 '11 at 20:25