How to read atom feed in .NET
I write code given below to read Atom feed.
string strUrL = "http://loluyede.blogspot.com/atom.xml";
WebRequest objWR = WebRequest.Create(strUrL);
WebProxy objWP = new WebProxy("strAddress", 1978);
objWP.Credentials = new NetworkCredential("username", "password");
objWR.Proxy = objWP;
StreamReader objSR = new StreamReader(objWR.GetResponse().GetResponseStream(), System.Text.Encoding.ASCII);
AtomFeed feed = AtomFeed.Load(objSR);
at the end of the statement following error comes
ERROR In Code:
The type initializer for 'Atom.Utils.DefaultValues' threw an exception.
ERROR on Page
Server Error in '开发者_如何转开发/WebAppUI' Application.
--------------------------------------------------------------------------------
Value cannot be null.
Parameter name: stream
Anybody suggest me what i have to do.
Have a look at thesyndication-namespace in System.ServiceModel.Syndicationfeed
It looks like you're using Atom.NET. That's 5 years old and supplied (as far as I can see) as a .NET 1.x assembly. That appears to be the problem - if you rebuild the bundled source in VS2005 or later then you'll get an assembly you can use.
Unfortunately I don't know the technical reason why the bundled binary doesn't work sorry.
The solution is much simpler:
string strUrl = "http://loluyede.blogspot.com/atom.xml";
Stream responseStream = WebRequest.Create(strUrl).GetResponse().GetResponseStream();
StreamReader objSR = new StreamReader(responseStream, System.Text.Encoding.UTF8);
string strTheWholeFeedAsString = objSR.ReadToEnd();
To get it fully up and running you should change from AtomFeed to ASP.Net RSS Toolkit (free from codeplex).
Good luck!
EDITED on 2010-09-12:
Given the fact, that the AtomFeed project is discontinued and written for .NET v1.1 therefore too old, I've created a sample application fetching your feed using RSS Toolkit. Feel free to download the source codes from http://www.isource.ro/StackOverflow/RssReaderTest.zip.
If you have questions don't hesitate to ask.
精彩评论