Using Yahoo Pipes as a Silverlight Cross Domain Proxy
May 12th 2008One of the cool features of Silverlight 2 is the support for cross-domain web requests. This enables you to call web APIs directly from your Silverlight client without proxying the request through your own server. The service you’re calling must provide a policy file permitting cross-domain callers. This is the same security mechanism used by Flash to make cross-domain calls, and in fact Silverlight 2 respects the same crossdomain.xml format as Flash. Any service callable by Flash is now callable by Silverlight 2. If you want to learn more about Silverlight networking and cross-domain calls check out Karen Corby excellent three part series on the Silverlight HTTP Network stack.
Several popular Web 2.0 services, like Flickr, have a crossdomain.xml file that allows for cross-domain Silverlight clients. Others, like Twitter, have a more restricted crossdomain.xml file that only allows callers from certain domains. Most sites however don’t provide a crossdomain.xml, so for instance if you want to consume their RSS feed you need to proxy the request through your server.
Today I started on a new Silverligh project where we want to consume RSS feed, and I was just about to add my “standard” WCF proxy to the project when my old friend Yahoo Pipes came to mind. I’ve previously blogged about how I use Yahoo Pipes to merge my blog posts with my mobile photos on Flickr and then import it to Facebook. Yahoo Pipes is a really cool service that let’s you define fairly complex web integrations using drag-and-drop. You drag different sources, filters and operations on a design service and “connect” the pipes together to pipe and transform the data. When I checked http://pipes.yahoo.com/crossdomain.xml I was a little disappointed to get a 404, but after digging around a little it turns out Yahoo host their APIs on a different URL: http://pipes.yahooapis.com/crossdomain.xml. Yahoo Pipes supports cross-domain callers!

I quickly created a really simple pipe. It uses the URL input module to retrieve the URL of the feed, the Feed-Fetch module to read the feed and then output it. Click for an example of my feed proxyed through Yahoo Pipes. The following code shows how to consume the feed in Silverlight 2:
I tried to make a more general purpose proxy-pipe using the “fetch data” module which can fetch XML, RSS, KML and iCal data. Unfortunately Yahoo Pipes can only output RSS, JSON or serialized PHP, but not plain XML. I tried piping my public Twitter feed (XML) through it, and it works fine. The only problem is that it makes some changes to the output, like adding the name of the pipe, the number of elements etc. So it’s not a “raw” data proxy, something you have to take in account when consuming the output of the pipe. Click for my Twitter feed outputted as a JSON array of tweets.
Below is a simple RSS reader (hosted on Silverlight streaming) I wiped up in 45 minutes that consumes any RSS feed through Yahoo Pipes! The code is off course available for download. For more Silverlight godness - come to REMIX!
Download