0

The code

XmlTextReader reader = new XmlTextReader("http://www.meloy.kommune.no/no/Abonner-pa-nyheter/Nyheter-Meloy-Kommune/");
DataSet ds = new DataSet();
ds.ReadXml(reader);

is causing this error when ds.ReadXml is called:

System.Net.WebException: The remote server returned an error: (500) Internal Server Error. at System.Net.HttpWebRequest.GetResponse() at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) 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.XmlReader.MoveToContent() at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving) at ASP.templates_units_rsslistingtest_ascx.LoadFeedServer(String url) at ASP.templates_units_rsslistingtest_ascx.SetupDataGridServer(Int32 max)

What is the cause of the error and how do I resolve it?

Edit: This works:

WebClient wc = new WebClient();
Stream st = wc.OpenRead("d:\\episerver\\test.xml");

        string rss ="";
        using (StreamReader sr = new StreamReader(st)) {
           rss = sr.ReadToEnd();
        }

         XmlReader reader = XmlReader.Create(new StringReader(rss));
        DataSet ds = new DataSet();
        ds.ReadXml(reader);         
Anders Branderud
  • 1,878
  • 6
  • 29
  • 45
  • try to specify the xmlSchema of your xml and then read the xml with dataset.. – Niranjan Singh Jan 18 '13 at 11:58
  • Try to download the file first and see if you can read it from localhost. That should at least give you some clarity to as where you have the error. – Moriya Jan 18 '13 at 12:02
  • @Animal, Thanks! It works when the file is located locally. However, not when I am downloading the file from here 'http://www.meloy.kommune.no/no/Abonner-pa-nyheter/Nyheter-Meloy-Kommune/' – Anders Branderud Jan 18 '13 at 12:17
  • However, I can visit the website 'http://www.meloy.kommune.no/no/Abonner-pa-nyheter/Nyheter-Meloy-Kommune/' without any problems from the server, where I am executing the code. – Anders Branderud Jan 18 '13 at 12:17
  • It works when I am using EPiServer's blog feed. Why does it work with one feed address and not another? – Anders Branderud Jan 18 '13 at 12:50

1 Answers1

1

I think it has something to do with the header created by C# web request. This thread that seems to deal with the same issue:

How do I read a secure rss feed into a SyndicationFeed without providing credentials?

Community
  • 1
  • 1
Moriya
  • 7,750
  • 3
  • 35
  • 53