RSS Feeds

Discussion in 'ASP .Net' started by sck10, Oct 3, 2006.

  1. sck10

    sck10 Guest

    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)
    sck10, Oct 3, 2006
    #1
    1. Advertising

  2. sck10

    Afton Wynona Guest

    you have to create a data source as well


    >
    Afton Wynona, Oct 3, 2006
    #2
    1. Advertising

  3. 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" wrote:

    > 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)
    >
    >
    >
    =?Utf-8?B?YnJpYW5zW01DU0Rd?=, Oct 3, 2006
    #3
  4. sck10

    sck10 Guest

    Thanks brians


    "brians[MCSD]" <> wrote in message
    news:...
    > 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" wrote:
    >
    >> 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)
    >>
    >>
    >>
    sck10, Oct 3, 2006
    #4
  5. 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.
    Steven Cheng[MSFT], Oct 4, 2006
    #5
  6. sck10

    sck10 Guest

    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







    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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.
    >
    sck10, Oct 4, 2006
    #6
  7. sck10

    sck10 Guest

    Hi Steven,

    The issue has been resolved.


    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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.
    >
    sck10, Oct 5, 2006
    #7
  8. 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.
    Steven Cheng[MSFT], Oct 9, 2006
    #8
  9. sck10

    sck10 Guest

    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


    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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.
    >
    sck10, Oct 10, 2006
    #9
  10. 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.
    Steven Cheng[MSFT], Oct 11, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken

    Rss News Feeds ???

    Ken, Oct 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    385
  2. Patrick Olurotimi Ige
    Replies:
    2
    Views:
    488
    Patrick Olurotimi Ige
    May 5, 2005
  3. Brian

    RSS Feeds On My Website

    Brian, Jun 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    409
    clintonG
    Jun 8, 2005
  4. Motta
    Replies:
    1
    Views:
    520
    Andy Dingley
    Jun 9, 2004
  5. Jonathan Groll
    Replies:
    1
    Views:
    261
    Kouhei Sutou
    Jun 27, 2009
Loading...

Share This Page