Implement RSS news feed in .Net

There are many ready to use RSS wrappers on the net, the one from Web Service Share is easy to use and comes on top from Google search.
Download two DLL,

  • Wss.Common.dll
  • Wss.News.WebService.PcWorldNews.GetDataFeed.dll

from Class Library add them to the Bin folder. Add the following snippet to the aspx markup.

<asp:Literal ID="Literal1" runat="server" EnableViewState="False"></asp:Literal>

The code behind file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using Wss.Common;
using WebServices = Wss.News.WebServices;
using Rss = Wss.News.Rss20;
 
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int _rssNum = 10;
        Rss.Result rssResult = WebServices.PcWorldNews.GetDataFeed();        
        foreach (var _rss in GetRss.SelectRss(rssResult,   _rssNum))
        {
            Literal1.Text += String.Format("<a href="{1}">{0}</a><br /><hr />", 
                _rss.Title, _rss.Link);
        }        
    }
}
 
public struct aRss {
    public string Title { get; set; }
    public string Link { get; set; }    
    //public string Description { get; set; }    
}
static public class GetRss {    
 
    static public List<aRss> SelectRss(Rss.Result rssResult, int _rssNum)
    {        
        List<aRss> allRss = new List<aRss>();
        for (int i = 0; i < Math.Min(_rssNum, rssResult.Items.Count); i++)
        {
            allRss.Add(new aRss
            {
                Title = rssResult.Items[i].GetTitle(""),
                Link = rssResult.Items[i].GetLink(""),
                //Description = _item.GetDescription("")                
            }
            );
        }        
        return allRss;
    }
}

The class will return only the first 10 entries. The number is specified by the variable “_rssNum”.

Add a lookup entry in local DNS

After you enter a web address, Windows OS will search a local DNS to find out corresponding IP address. If it could not find it there, it will go to DNS server to search for it. Old days people used to add those often visited addresses to a local DNS file to seep up the Internet surfing experience. Currently with hi peed Internet connection, the practice will not yield any noticeable difference. However, if you have a intranet and you want to go to internal address by calling its external address, that is the way to go.
To edit your local DNS lookup file, go to
C:WindowsSystem32Driversetc
Using a text editor like notepad to open the file hosts
Add an entry at the bottom with two information: the IP address and the customized domain name, separated by a single space.
192.168.1.5 wukenny.homeserver.com
192.168.1.5 www.wukenny.homeserver.com

This works in both windows xp and windows 7. In Win7 you might need to copy the file to another location get it edited and then pasted it back due to the stringent user control.

How to Retrieve HTTP content in .NET

HttpWebRequest and HttpWebResponse greatly simplified http content retrial process. Code snippet below demonstrated how easy to use.

using System;
using System.Text;
using System.Net;
using System.IO;
 
static void Main(string[] args)
{
    string webUrl = "http://www.google.com";
    WebRequest req = WebRequest.Create(webUrl);
    req.Timeout = 10000;
    WebResponse resp = req.GetResponse();
    StreamReader reader = new StreamReader(resp.GetResponseStream(), Encoding.ASCII);
    Console.WriteLine(reader.ReadToEnd());
    resp.Close(); // Close the response to free resources.
    reader.Close();
}

Simple and elegant. To look for more…Retrieving HTTP content in .NET