Filed under:
euicommunity — jordan.snyder @ 7:59 pm
As mentioned in my brief talk at Microsoft MIX 09 a few weeks ago, we are working on a Silverlight application for a major photo-sharing website. This is the first post of a couple that will explain a few issues we ran into while developing a Silverlight 2 application.
First, Silverlight does not support rendering of GIF images with the <Image> component. You can use a component from ComponentOne to display GIF’s, but it uses WebClient or HTTPRequest to grab the raw image data to process, and therefore becomes restricted by cross-domain security policies. You can find a very clear explanation of Silverlight’s URL security restrictions here, but to summarize, the <Image> and <MediaElement> components are more lax when loading from one domain to another (they do not require that crossdomain policy files live on the server) so you are allowed to load content from domains other than the one that the Silverlight app was served from. However, when using WebClient or HTTPRequest directly (or direct sockets, for that matter), you must have crossdomain policy files on the deploying server.
So, how is this worked around? You can do a few things:
1. Set up a web server proxy solution - Server-side code does not have crossdomain restrictions, so you can deploy server-side code (on the server that is serving the Silverlight application) that will broker requests from the Silverlight client application, go out and get data from wherever you need it, and then tunnel it back through to Silverlight. This has been done for years with Flash and AJAX server requests, but in my opinion, it’s still as messy as ever. Thinking about it just makes me feel a bit dirty.
2. Deploy crossdomain policy files to ALL servers hosting image content - This means that the “major photo-sharing website” that I mentioned above will have to do some work. Fortunately for us, they are in the process of doing this anyway, but if they weren’t, this wouldn’t quite be an option. Quite a few public API’s do have crossdomain policy files in place for this very reason, but many don’t (including Twitter’s API).
3. Host the Silverlight application on a subdomain off of the same domain as the images? - In other words, can we host the application on http://search.yourphotosite.com and access images on http://images1.yourphotosite.com and http://images32.yourphotosite.com? The short answer is no, not without crossdomain policy files…which, according to #2 above, would solve our problem anyway. So, that doesn’t get us anywhere either!
4. When the API returns with a list of images, filter out all images ending in “.gif” - Okay, this is easy to filter out, but not so easy when dealing with the total number of results. We pagination results and show the total, so if the API says there are 4000 images and 2000 of those are GIF’s, we’re going to have a completely incorrect count at all times. Since this is public and popular image-sharing, there are A LOT of GIF’s. This option definitely does not solve the problem.
As far as I know, these are the only options available in this particular instance. We are hoping that the photo-sharing site will expedite the installation of the crossdomain policy files on their image content servers, but without that, we’d be out of luck.
Posted in euicommunity | No Comments »