0
votes

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);         
1
try to specify the xmlSchema of your xml and then read the xml with dataset..Niranjan Singh
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
@Animal, Thanks! It works when the file is located locally. However, not when I am downloading the file from here 'meloy.kommune.no/no/Abonner-pa-nyheter/Nyheter-Meloy-Kommune'Anders Branderud
However, I can visit the website 'meloy.kommune.no/no/Abonner-pa-nyheter/Nyheter-Meloy-Kommune' without any problems from the server, where I am executing the code.Anders Branderud
It works when I am using EPiServer's blog feed. Why does it work with one feed address and not another?Anders Branderud

1 Answers

1
votes

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?