Earthquake Locator - Live Demo and Source Code
- by Bobby Diaz
Quick Links
Live Demo
Source Code
I finally got a live demo up and running! I signed up for a shared hosting account over at discountasp.net so I could post a working version of the Earthquake Locator application, but ran into a few minor issues related to RIA Services. Thankfully, Tim Heuer had already encountered and explained all of the problems I had along with solutions to these and other common pitfalls. You can find his blog post here. The ones that got me were the default authentication tag being set to Windows instead of Forms, needed to add the <baseAddressPrefixFilters> tag since I was running on a shared server using host headers, and finally the Multiple Authentication Schemes settings in the IIS7 Manager.
To get the demo application ready, I pulled down local copies of the earthquake data feeds that the application can use instead of pulling from the USGS web site. I basically added the feed URL as an app setting in the web.config:
<appSettings>
<!-- USGS Data Feeds: http://earthquake.usgs.gov/earthquakes/catalogs/ -->
<!--<add key="FeedUrl"
value="http://earthquake.usgs.gov/earthquakes/catalogs/1day-M2.5.xml" />-->
<!--<add key="FeedUrl"
value="http://earthquake.usgs.gov/earthquakes/catalogs/7day-M2.5.xml" />-->
<!--<add key="FeedUrl"
value="~/Demo/1day-M2.5.xml" />-->
<add key="FeedUrl"
value="~/Demo/7day-M2.5.xml" />
</appSettings>
You will need to do the same if you want to run from local copies of the feed data. I also made the following minor changes to the EarthquakeService class so that it gets the FeedUrl from the web.config:
private static readonly string FeedUrl = ConfigurationManager.AppSettings["FeedUrl"];
/// <summary>
/// Gets the feed at the specified URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>A <see cref="SyndicationFeed"/> object.</returns>
public static SyndicationFeed GetFeed(String url)
{
SyndicationFeed feed = null;
if ( !String.IsNullOrEmpty(url) && url.StartsWith("~") )
{
// resolve virtual path to physical file system
url = System.Web.HttpContext.Current.Server.MapPath(url);
}
try
{
log.Debug("Loading RSS feed: " + url);
using ( var reader = XmlReader.Create(url) )
{
feed = SyndicationFeed.Load(reader);
}
}
catch ( Exception ex )
{
log.Error("Error occurred while loading RSS feed: " + url, ex);
}
return feed;
}
You can now view the live demo or download the source code here, but be sure you have WCF RIA Services installed before running the application locally and make sure the FeedUrl is pointing to a valid location. Please let me know if you have any comments or if you run into any issues with the code.
Enjoy!