RSS Feeds

S

sck10

Hello,

I am trying to learn how to consume RSS feeds and downloaded the example
from the MSDN site:

http://msdn.microsoft.com/coding4fun/xmlforfun/simplerss/default.aspx?print=true


However, I am getting the following error at:
rssData.ReadXml(rssFeed.GetResponse().GetResponseStream()); even though I
can go directly to the site.

Any help with this would be appreciated.

Thanks, sck10



private DataSet RefreshFeed()
{
HttpWebRequest rssFeed =
(HttpWebRequest)WebRequest.Create("http://msdn.microsoft.com/vbasic/rss.xml");

DataSet rssData = new DataSet();
rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());

return rssData;
}


Error Statement
+++++++++++++++++++++
System.Net.WebException was unhandled by user code
Message="Unable to connect to the remote server"
Source="System"
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at RssList.RefreshFeed() in
c:\Inetpub\wwwroot\gsttcsharp\ztest\rss\RssList.ascx.cs:line 30
at RssList.Page_Load(Object sender, EventArgs e) in
c:\Inetpub\wwwroot\gsttcsharp\ztest\rss\RssList.ascx.cs:line 12
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.BasePartialCachingControl.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
G

Guest

Hello sck10,

A simplified way to consume an RSS feed. Place a data repeater rptrRssFeed
on your web form:

XmlReader rssReader = new XmlTextReader(rssUrl);
DataSet ds = new DataSet();
ds.ReadXml(rssReader);

rptrRssFeed.DataSource = ds.Tables["item"];
rptrRssFeed.DataBind();

Add support for caching and exception handling to make it more robust.
 
S

sck10

Thanks brians


brians said:
Hello sck10,

A simplified way to consume an RSS feed. Place a data repeater rptrRssFeed
on your web form:

XmlReader rssReader = new XmlTextReader(rssUrl);
DataSet ds = new DataSet();
ds.ReadXml(rssReader);

rptrRssFeed.DataSource = ds.Tables["item"];
rptrRssFeed.DataBind();

Add support for caching and exception handling to make it more robust.
--
brians
http://www.limbertech.com


sck10 said:
Hello,

I am trying to learn how to consume RSS feeds and downloaded the example
from the MSDN site:

http://msdn.microsoft.com/coding4fun/xmlforfun/simplerss/default.aspx?print=true


However, I am getting the following error at:
rssData.ReadXml(rssFeed.GetResponse().GetResponseStream()); even though I
can go directly to the site.

Any help with this would be appreciated.

Thanks, sck10



private DataSet RefreshFeed()
{
HttpWebRequest rssFeed =
(HttpWebRequest)WebRequest.Create("http://msdn.microsoft.com/vbasic/rss.xml");

DataSet rssData = new DataSet();
rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());

return rssData;
}


Error Statement
+++++++++++++++++++++
System.Net.WebException was unhandled by user code
Message="Unable to connect to the remote server"
Source="System"
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at RssList.RefreshFeed() in
c:\Inetpub\wwwroot\gsttcsharp\ztest\rss\RssList.ascx.cs:line 30
at RssList.Page_Load(Object sender, EventArgs e) in
c:\Inetpub\wwwroot\gsttcsharp\ztest\rss\RssList.ascx.cs:line 12
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.BasePartialCachingControl.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
S

Steven Cheng[MSFT]

Hello Steve,

Have you got the code working?

From the original error info and callstack you provided, the problem is
likely due to the web access through the HttpWebRequest class( exception
raises at WebRequest.GetResponse ...).

When using httpwebrequest, one thing we'd take care is whether the
webrequest component can get a correct web proxy (if it is required in the
certain network environment). You can try using the system's default proxy
(from IE setting...) or explicitly specify a proxy. e.g.

==================
protected void Page_Load(object sender, EventArgs e)
{
HttpWebRequest request =
WebRequest.Create("http://msdn.microsoft.com/vbasic/rss.xml") as
HttpWebRequest;

request.Method = "GET";
request.Proxy = WebProxy.GetDefaultProxy();
//request.Proxy = new WebProxy("myproxy", 80);

HttpWebResponse response = request.GetResponse() as HttpWebResponse;


Stream stream = response.GetResponseStream();

DataSet ds = new DataSet();
ds.ReadXml(stream);

stream.Close();
response.Close();


GridView1.DataSource = ds.Tables["item"];
GridView1.DataBind();
}
==================

Hope this helps also.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

sck10

Hi Steven,

I tried your code, but I got the error:
System.Net.WebProxy.GetDefaultProxy()' is obsolete.

Also, I have created a page that uses the XmlDataSource control

<asp:XmlDataSource runat="server"
ID="XmlDataSource"
DataFile="~/ztest/rss/msdnvb.xml"
XPath="rss/channel/item" />

and I created a page that calls the XmlTextReader:
try
{
string rssUrl = "http://msdn.microsoft.com/vbasic/rss.xml";
//rssUrl = "http://myxml.com/ztest/rss/msdnvb.xml";
XmlReader rssReader = new XmlTextReader(rssUrl);
DataSet ds = new DataSet();
ds.ReadXml(rssReader);

rptRSS.DataSource = ds.Tables["item"];
rptRSS.DataBind();
}

catch(Exception ex)
{
this.lblMessageText.Text = "RSS Feed Error: " +
ex.Message.ToString();
}

When I run the last two pages, I get the error: "Unable to connect to the
remote server". So I copied the xml file
(http://msdn.microsoft.com/vbasic/rss.xml) and the xsl file from the
Microsoft site to my site. When I did that, I could read the file in both
pages. However, I am unable to pull the file from other sites. Do you
think this relates to the original problem that you addressed?

By the way, which method would you prefer? the XmlDataSource control or
using XmlTextReader?

Thanks again, sck10
 
S

Steven Cheng[MSFT]

Thanks for your followup Steve,

Glad that you've got the issue resolved.

BTW, it would also be great that if you can share your final solution with
us, that will be helpful to other members also.

Have a good day!


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

sck10

Hi Walter,

This is what I am using, but you also suggested that I use a custom tool:

try
{
WebRequest req =
WebRequest.Create(http://rss.cnn.com/rss/cnn_topstories.rss);

// Get Website Proxy
req.Proxy = new WebProxy("global.proxy.lucent.com:8000", true);
req.Proxy.Credentials = CredentialCache.DefaultCredentials;
WebResponse resp = req.GetResponse();

// Stream the data
StreamReader textReader = new StreamReader(resp.GetResponseStream());
XmlTextReader xmlReader = new XmlTextReader(textReader);
//XmlReader rssReader = new XmlTextReader(rssUrl);

// Build Dataset
DataSet dsRSS = new DataSet();
dsRSS.ReadXml(xmlReader);

// Populate Repeater Tool
rptRSS.DataSource = dsRSS.Tables["item"];
rptRSS.DataBind();
}

catch(Exception ex)
{
this.pnlMessage.Visible = true;
this.lblMessageTitle.Text = "RSS Feed Error";
this.lblMessageText.Text =
"<span class=BlkB>Record Not Found</span><br />" +
"Problems consuming RSS Feed for" +
"<br /><br /><span class=BlkB>RSS Feed Error</span><br />" +
ex.Message.ToString();
}

Regards, sck10
 
S

Steven Cheng[MSFT]

Hi Steve,

Thanks for the followup and sharing the code with us.

BTW, I think you've mistaken me with Walter as Walter has also worked with
you in anthoer thread :)

Have a good day!


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top