More on GeoRSS...

1089
10
02-03-2011 05:56 AM
adamestrada
New Contributor
If you check out this example with the 7 day earthquake feed it works just fine.

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#GeoRSS

Plug any other GeoRSS feed in there (http://www.openstreetmap.org/traces/rss) and it doesn't work. Debugging it says there is a security issue but I've added my clientaccesspolicy.xml file to my project like suggested on several message boards. The contents are as follows.

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*" >
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>


Why won't any other GeoRSS feeds work. I've basically copied the aforementioned example line by line. Suggestions are welcome!!!  I've attached my code page but basically the method that does all the parsing is this one.

 #region Parse GeoRSS with Linq
        private void RSS(Stream s)
        {
            try
            {
                GraphicsLayer graphicsLayer = Map.Layers["GeoRSSFeed"] as GraphicsLayer;
                graphicsLayer.ClearGraphics();

                XDocument doc = XDocument.Load(s);
                XNamespace geo = "http://www.w3.org/2003/01/geo/wgs84_pos#";
                XNamespace dc = "http://purl.org/dc/elements/1.1/";

                var rssGraphics = from rssgraphic in doc.Descendants("item")
                                  select new RssGraphic
                                  {
                                      Geometry = new MapPoint(
                                          Convert.ToDouble(rssgraphic.Element(geo + "long").Value, System.Globalization.CultureInfo.InvariantCulture),
                                          Convert.ToDouble(rssgraphic.Element(geo + "lat").Value, System.Globalization.CultureInfo.InvariantCulture)),
                                      Symbol = LayoutRoot.Resources["QuakePictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                                      RssAttributes = new Dictionary<string, object>() { { "Title", rssgraphic.Element("title").Value },
                                                                                     { "Link", rssgraphic.Element("link").Value } }
                                  };

                foreach (RssGraphic rssGraphic in rssGraphics)
                {
                    rssGraphic.Geometry = _mercator.FromGeographic(rssGraphic.Geometry);
                    foreach (KeyValuePair<string, object> rssAttribute in rssGraphic.RssAttributes)
                    {
                        rssGraphic.Attributes.Add(rssAttribute.Key, rssAttribute.Value);
                    }
                    graphicsLayer.Graphics.Add((Graphic)rssGraphic);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        #endregion


Thanks,
Adam Estrada
0 Kudos
10 Replies
DanielWalton
Occasional Contributor
Adding a clientaccesspolicy.xml file to your project does not mean anything. The file at http://www.openstreetmap.org/clientaccesspolicy.xml is what defines how Silverlight can access resources, and that file restricts client access to OSM api and oauth endpoints:

<grant-to>
<resource path="/api" include-subpaths="true"/>
<resource path="/oauth" include-subpaths="true"/>
</grant-to>

Just setup a proxy handler in your web project. There are numerous examples of how to do this on the forums and interactive samples. (BTW the earthquake sample data comes from USGS, and the file http://earthquake.usgs.gov/crossdomain.xml is less restrictive.)
0 Kudos
adamestrada
New Contributor
Would never have thought of that...is there any way you could point to an example where a proxy is used in a SilverLight Project? I am very new to SL.

Thanks in advance,
Adam
0 Kudos
DanielWalton
Occasional Contributor
Here's a simple Proxy handler that would go in your web project:

using System;
using System.Net;
using System.Web;

namespace MySilverlightProject.Web
{
    public class SimpleHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var bytes = (new WebClient()).DownloadData(new Uri(context.Request["url"]));
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.BufferOutput = false;
            context.Response.BinaryWrite(bytes);
        }
        public bool IsReusable { get { return false; } }
    }
}
Instead of pointing to http://www.openstreetmap.org/traces/rss, you would reference http://myserver/mypath/myproxy.ashx?url=www.openstreetmap.org/traces/rss instead.
0 Kudos
adamestrada
New Contributor
Thanks! I came across this guy after some Googling but it seems like overkill.

http://www.eggheadcafe.com/tutorials/aspnet/45d1dc2b-7db7-4bbc-b612-003fe889ed4a/silverlight-multipu...

I will try your approach right now...

Thanks again,
Adam
0 Kudos
adamestrada
New Contributor
danwallie,

Your method works like a charm! The other one didn't...KISS, huh...

Thanks,
Adam
0 Kudos
HunterPerkins1
New Contributor
I seem to be having the same problem with accessing other georss feeds other than the earthquake examples. I am very unfamiliar with creating proxy files and new to C# and Silverlight. Is there any way someone could post a complete solution? Or expand on how the proxy file is implemented and provide a more descriptive example of the pointer used to access the feed? Thank You!
0 Kudos
adamestrada
New Contributor
No problem...This was new to me too.

1. In your Silverlight.Web project create a generic web handler and call it "proxy.ashx" or something like that.

Copy this code in to that file.

using System;
using System.Collections.Specialized;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Web;

namespace Viewer.Web
{
    /// <summary>
    /// Summary description for proxy
    /// </summary>
    public class proxy : IHttpHandler
    {

         public void ProcessRequest(HttpContext context)
        {
            {
                var bytes = (new WebClient()).DownloadData(new Uri(context.Request["url"]));
                context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                context.Response.BufferOutput = false;
                context.Response.BinaryWrite(bytes);
            }
        }
        public bool IsReusable { get { return false; } }
    }
}


2. I your xaml code behind, include the proxy page in your code. Mine was as simple as this method.

        #region Load GeoRSS Feeds
        private void LoadFeeds()
        {
            try
            {
                String uri = Configuration.getLocalAppSetting("homeURL");
                String url = Configuration.getRSSAppSetting(param);
                LoadRSS(uri + "proxy.ashx?url=" + url);
                DispatcherTimer UpdateTimer = new DispatcherTimer();
                UpdateTimer.Interval = new TimeSpan(0, 0, 0, 60, 0);
                UpdateTimer.Tick += (evtsender, args) =>
                {
                    LoadRSS(uri + "proxy.ashx?url=" + url);
                };
                UpdateTimer.Start();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        #endregion


I hope this helps!
Adam
0 Kudos
HunterPerkins1
New Contributor
Thank you Adam your example really helped me see what needed to be done. However, I'm still having trouble! I am able to create a new url based on the format presented by Dan, which is the following:

http://localhost:50025/ClientBin/ArcGISSilverlightSDK.xap/proxy.ashx?url=www.openstreetmap.org/trace...

I have also tried the example provided by Peter Bromberg, which produced:

http://localhost:50025/proxy.ashx?url=www.openstreetmap.org/traces/rss

But, neither seem to load new locations based on the feed, even when trying the earthquake feed from USGS. Do you know if the url that you are creating is the same format as the ones I am attempting to load? If you could provide me of a sample url that works for you, I think I might be able to get this thing working. Thank you for all your help!
0 Kudos
adamestrada
New Contributor
The only difference I can see is that mine uses the full URL including the http://

Http://localhost:1234/proxy.ashx?URL=http://earthquakefeed.xml

Adam
0 Kudos