Results 1 to 7 of 7

Thread: Feed Viewer using asp.net

  1. #1

    Default Feed Viewer using asp.net

    Hi,
    I have tried to create a asp.net verison of feed.php and it doesnt seem to work.

    My ashx file:


    Code:
    Next line enclosed within <> tags
     %@ WebHandler Language="C#" Class="Feed" % 
    using System;
    using System.Web;
    using System.Xml;
    
    public class Feed : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            try
            {
                string url = context.Request["feed"];
                if (!string.IsNullOrEmpty(url) && url.StartsWith("http"))
                {
                    context.Response.ContentType = "text/xml";
                    XmlTextReader xtr = new XmlTextReader(url);
                    context.Response.Write(xtr.ReadInnerXml());
                    xtr.Close();
                }
                else
                    context.Response.Write("Feed Url Error in " + url);
            }
            catch (Exception ex)
            {
                context.Response.Write("exp " + ex.Message);
            }
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    the error on accessing
    http://localhost/yui//Feed.ashx?feed....com%2Fajaxian
    Code:
    The XML page cannot be displayed 
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 
    
    
    --------------------------------------------------------------------------------
    
    A name was started with an invalid character. Error processing resource 'http://localhost/yui/Feed.ashx?feed=http%3A%2F%...
    
    <WebHandler>
    -^
    Following is the error in the first line of the ashx file in VS2005. This line is auto-generated and how does this have error?

    ASP.NET runtime error: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

    Any suggestions please??
    Thanks

  2. #2
    Ext User rodiniz's Avatar
    Join Date
    Mar 2007
    Location
    Rio de Janeiro, Brazil
    Posts
    276

    Default

    You cannot use XmlTextReader to read an rss feed.
    You need to use a component like
    rss.net
    http://www.rssdotnet.com/
    I can give a sample on using this component , my sample is not generating xml like you want
    but I think you will have some starting point.
    My e-mail is at my website.

  3. #3

    Default

    Hi,
    I don't get one point i.e. why do I need a component to simply read a rss(xml) file and send it as a xml response over XHR.
    Please help me on this. I need to complete on this topic ASAP.
    Thanks

  4. #4
    Ext User rodiniz's Avatar
    Join Date
    Mar 2007
    Location
    Rio de Janeiro, Brazil
    Posts
    276

    Default

    You could use the System.net.Weclient class
    Code:
    WebClient cli = new WebClient();
    byte[] data = cli.DownloadData(Url);
    string texto = System.Text.Encoding.UTF8.GetString(data);
    context.Response.Write(texto);
    But will get all the posts from the rss feed... and that can take a lot of time.
    But it will work. With the component you can download only the latest 10 feeds (for example)
    wich will much faster.

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956

    Default

    This is completely untested and I just typed it into this window, but it should work.

    Code:
                string url = context.Request["feed"];
                if (!string.IsNullOrEmpty(url) && url.StartsWith("http"))
                {
                    context.Response.ContentType = "text/xml";
                    HttpWebRequest http = WebRequest.create(url);
                    HttpWebResponse response = http.GetResponse();
                    StreamReader s = new StreamReader(response.GetResponseStream());
                    string result = s.ReadToEnd();
                    context.Response.Write(result);
                 }
                else
                    context.Response.Write("Feed Url Error in " + url);

  6. #6

    Default

    Hi Jack,
    The commented lines were flagging error cannot convert webrequest/response object to httpwebrequest/response( rightly so), so i changed them but still no result..
    There still exists some error
    Code:
                    WebRequest http = HttpWebRequest.Create(url);
                    //HttpWebRequest http = WebRequest.Create(url);
                    //HttpWebResponse response = http.GetResponse();
                    WebResponse response = http.GetResponse();
                    StreamReader s = new StreamReader(response.GetResponseStream());
                    string result = s.ReadToEnd();
                    context.Response.Write(result);
    and this version also
    Code:
                    HttpWebRequest http = WebRequest.Create(url) as HttpWebRequest ;
                    using (HttpWebResponse response = http.GetResponse() as HttpWebResponse)
                    {
                        StreamReader s = new StreamReader(response.GetResponseStream());
                        string result = s.ReadToEnd();
                        context.Response.Write(result);
                    }
    Response received in both cases:
    exceptionUnable to connect to the remote server::inner exception) System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)

    Hi rodinz,
    I tried your version too, the response received is same? :cry:

    Is this some thing related to Proxy servers?

  7. #7
    Ext User
    Join Date
    Dec 2008
    Location
    Netherlands
    Posts
    16

    Default

    I had the same problem with requesting it on windows server for some security reasons...

    I did a simple solution in FeedGrid.js i requested the page directly.

    this.store = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
    url: 'feed-proxy.aspx'
    }),

    and in the .net i created my RSS with Request.Form("Feed") with the conditions.

    you can create whatever you wish in this condition inside your page with if else or case condition.

    and in the RSS

    feeds.addFeed({
    url:'news',
    text: 'view all news'
    }, true);

Similar Threads

  1. Rss Feed Viewer
    By gizzmo in forum Ext 1.x: Help & Discussion
    Replies: 17
    Last Post: 3 Mar 2009, 5:15 PM
  2. Rss Feed Viewer 2.0 using RoR
    By amitava in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 8 Jan 2009, 6:16 AM
  3. feed viewer problem
    By Bobafart in forum Ext 1.x: Help & Discussion
    Replies: 8
    Last Post: 26 Jan 2007, 7:49 AM
  4. Can't get the rss feed viewer to work
    By ib in forum Ext 1.x: Help & Discussion
    Replies: 16
    Last Post: 6 Jan 2007, 9:21 AM
  5. Feed Viewer 2
    By zquirm in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 24 Nov 2006, 5:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •