CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

RSS in my Real Job - Container Tracking via RSS

Last week, my boss asked me if I knew anything about this new “RSS” technology, and wondered if I thought there was any use for it in our business.  I was immediately struck by all of the ways we could integrate RSS into our information offerings here at the port.  Most of what we do in the web group here  is come up with new ways to increase the accessibility of information to our different types of customers.  They all have slightly different needs, but most of these needs revolve around one all important question: “Where is my container?”

Guess what? RSS makes perfect sense for tracking containers!  The idea we had was that a customer could subscribe to a Container’s RSS feed, and get updates whenever there was a status change for that container.  We had just found the killer business app for RSS, we thought.  Well, as it turns out (as it always does), we weren’t the first (or even the second) group to have this bright idea.  In fact, you can read all about tracking packages with RSS over at XML.com: Tracking Packages with RSS.

The idea of using RSS for tracking packages is not mine. Back in July of 2004, Ben Hammersley wrote a screen scraping script for parsing HTML data produced by FedEx's online tracking system into RSS. Unfortunately, screen scraping is often unreliable, since carriers can change their websites at any time. This led to the creation of a UPS tracking service as a .net dll by Jason Young in December of 2004 that utilized UPS's XML API instead of screen scraping. Because I wanted something that would run on Linux without Project Mono, I chose to write my own alternative and with that the track2rss project was born. Current support is provided for FedEx, UPS and USPS, with DHL USA support coming soon.

It still being a great idea, I spent the better part of the day working on an RSS feed syndication engine for use here at the port.  The only real difference between the FedEx solution and ours is that our packages are made of steel and are about 40 feet long.

The Solution

The solution turned out to be so simple, it doesn’t even really deserve much explanation.  Basically, I just hooked an IHttpHandler which creates an RSS feed, and adds an item for each ContainerEvent (arrive, depart, ready for pickup, etc.)

For the RSS feed building, I used the Racoom.XML (yes that’s racoom, not racoon – try reading that all day without getting a little nutty).

The Code Project - RSS 2.0 Framework - C# Programming
RSS 2.0 framework implements the RSS 2.0 specification in strongly typed classes. The framework enables you to create and consume valid RSS 2.0 feeds in your code in just a few minutes.

It really did work as promised, it’s a very well designed library.  Here’s my IHttpHandler Code that creates the feed:

    ///

    /// Processs the request.

    ///

    /// Context.

    public void ProcessRequest(HttpContext context)

    {

      string containerNumber = context.Request.Params["CONTAINER"];

 

      if(containerNumber != null && containerNumber.Length > 0)

      {

        containerNumber = ContainerUtils.AddCheckDigit(containerNumber);

 

        // create channel

        RssChannel myChannel = new RssChannel();

        myChannel.Title = String.Format("VIT Container RSS ({0})", containerNumber);     

        myChannel.Copyright = "Copyright 2005, Virginia International Terminals, Inc.";

        myChannel.TTL = 20;

        myChannel.Generator = "VIT RSS Handler version 1.0";

 

        //get the data … code removed for security

 

        if(historyEvents.Count > 0)

        {

          myChannel.PubDate = historyEvents[0].ServiceDate;

 

          foreach(ContainerHistoryEvent historyEvent in historyEvents)

          {

            // create item

            RssItem myRssItem = new RssItem();

            myRssItem.PubDate = historyEvent.ServiceDate;

            myRssItem.Title = historyEvent.EventDescription;

            myRssItem.Description = historyEvent.ToHtml();

            myRssItem.Link = VIT.Common.Util.ContainerUtils.GetPublicContainerTrackingUrl(containerNumber);

            myRssItem.Source.Url = context.Request.Url.AbsoluteUri;

 

            // add item

            myChannel.Items.Add(myRssItem);

          }

        }

 

        context.Response.ContentEncoding = Encoding.UTF8;

        context.Response.ContentType = "text/xml";

        myChannel.Save(context.Response.OutputStream);

 

       }

    }

And here’s what it looks like in JetBrain’s Omea Reader:

You can see that this container has had three events so far.  As it goes through it’s life-cycle here at the port, it’ll have a bunch more, and they’ll pop up in the end user’s RSS reader. 

Now, I’m fairly certain that most of our end users won’t be using this anytime soon, but for us, it was a no-brainer to implement.  We already have our re-usable service tier in place, so it’s just one more way to provide our customers visibility of their shipments.  I also have confidence that RSS and other similar technologies are going to scale after all and will be used for lots of stuff in the future.  Finally, for the one or two people that actually do end up using this feed to track their containers in the near future?  Well, how cool is that?

-Brendan



Comments

Steve said:

Cool stuff. You gotta love when your boss comes to you asking about something that you've been dying to use at your gig.
# April 25, 2005 2:45 PM

Brendan Tompkins said:

Steve,

No kidding! I was aching to start coding this last week, but I was buried under work. Now if he'll only ask me to write an MP3 app. :)
# April 25, 2005 5:19 PM

Sam said:

That's the coolest thing I've ever seen. I mean, way to break the "We deliver content through our web-site" mold!
# April 25, 2005 8:58 PM

Dmitry said:

Brendan, great information. I work at a IMC company and we need to get container tracking info from all the shipping companies from all the ports. Where do I go to get access to the feeds? Please advise.
# November 7, 2005 10:03 PM

Chris Richner aka Jerry Maguire said:

Never thought that my rss code is involved in tracking containers on the other side of the world ;)

"It really did work as promised, it’s a very well designed library."
Thanks...
# February 15, 2006 5:48 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Brendan Tompkins

Brendan has been programming with .NET since the first public beta and is owner and operator of Port Technology Services, a consultancy company providing .NET application development services to the Maritime industry. In July, 2007, he was awarded the Microsoft MVP award for ASP.NET. He's also a proud co-founder of failed .COM startup Intrinsigo, and has had a hand in the failure of numerous other businesses. He currently runs CodeBetter.Com and Devlicio.us, and lives in Norfolk, Virgina with his wife Tiara and son Ian.

View Brendan's profile on LinkedIn

Check out Devlicio.us!

Our Sponsors

Free Tech Publications