Silverlight 2.0 and network cross domain calls

After reading Scott Guthries silverlight 2.0 using networking to retrieve data and populate a datagrid tutorial I decided to try and make a little Silverlight 2.0 banner that displays my recent tracks from the Last.FM through their great  webservices with some nifty graphics.

I decided to use the same code as Scott and use the WebClient class to download the xml asynchronously. After implementing and running the code I get a “Security Error” exception on DownloadStringAsync. It appears you have to run the Silverlight app on a hosted HTML on IIS instead of a HTML file on a local drive, pretty strange in my opinion, see for more.

After hosting my html on IIS I get an empty screen, no Exceptions. Scott uses the following code to fill the datagrid after the data is downloaded:

void recentTracksService_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
if (e.Error == null)
RecentTrackList.ItemsSource = LastFMServices.Stats.getRecentTraks(e.Result);

I decided to place a breakpoint on e.Error, and it turned out it did contain an error: “Download Failure”. That’s pretty strange? When using the Digg link from Scotts sample I get data from the webservice. When reading Scotts Blog again I came across the following text: “Silverlight 2 defines an XML policy file format that allows server administrators to precisely control what access a client should have. Silverlight 2 also honors the default Flash cross domain policy file format – which means that you can use Silverlight 2 to call any existing remote REST, SOAP/WS*, RSS, JSON or XML end-point on the web that already enables cross-domain access for Flash clients. has a pretty cool set of Digg APIs that they publish over HTTP. Because they have a Flash cross-domain policy file in place on their server, we can call them directly from our Silverlight Digg client application (and not require us to tunnel back through our web-server to reach their APIs).”

Hmm it appears Last.FM doesn’t honor the Flash cross domain policy file format or the new Microsoft cross domain XML files. I’ll post a request at the Last.FM forum to add those XML files to the server, I hope they’ll allow it.

Read this on: how to make a Service Available Across Domain Boundaries

Some further info on Webservices and Silverlight:
Sending and Receiving Plain XML Messages with Silverlight
WebClient..::.DownloadStringAsync Method (Uri)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.