4Blogging – External Image Hosting – Picasa – Part 2

After an initial exploration into the options for connecting a Silverlight application to a Picasa image library a strategy was formed to retrieve metadata via a WCF RIA Domain service and load the images directly from Picasa. This get round the issue of Silverlight making cross domain calls to third party services without a cross domain policy.

I have prototyped a solution which can be downloaded from the sister codeplex site:


This is a very simple project that just demonstrates the possibility of interaction between the two technologies. It is not thorough in quality, validation or error handling. It does however demonstrate calling a Picasa album from Silverlight given a user name and album Id (These need to be replaced in the solution with your own library for it to work). 
As there are no data entities created the return is a list of a custom class which has the requirement to be serializable and have an entity key.

The Silverlight application creates a Domain Service context and Entity Query with the user name and album id and calls a Load Operation on the context and adds an event handler to the callback.


            PicasaGoogleContext context = new PicasaGoogleContext();
            EntityQuery<ImageItem> query = context.GetAlbumImagesQuery("user.name""albumid");

            LoadOperation<ImageItem> queryOperation = context.Load(query);
            queryOperation.Completed += new EventHandler(queryOperation_Completed);


If the operation has been successful new images are created from the result and added to the StackPanel.


            LoadOperation<ImageItem> queryOperation = sender as LoadOperation<ImageItem>;
            if (queryOperation.Error == null)
                foreach (ImageItem img in queryOperation.Entities)
                    Image img1 = new Image();
                    img1.Source = new BitmapImage(new Uri(img.ThumbSmall, UriKind.Absolute));
                    img1.Width = 100;
                    img1.Height = 100;


The Domain Service makes the call to the Picasa service to retrieve the feed for photo items by user and album. This feed is then used to populate the ImageItem with the thumbnail and full image url as well as the filename. The list of these ImageItems are then returned.


            List<ImageItem> images = new List<ImageItem>();

            PicasaService service = new PicasaService("PicasaGoogleImageService");
            PhotoQuery query = new PhotoQuery(PicasaQuery.CreatePicasaUri(user, album));
            PicasaFeed feed = service.Query(query);

            foreach (PicasaEntry entry in feed.Entries)
                ImageItem item = new ImageItem(entry.Title.Text, 


            return images;


From an application viewers perspective the Silverlight application loads and the images appear in the application shortly after, this successfully demonstrates the process. Additional features required for a full blown implementation would include security and navigation of albums before reaching an image selection with lightbox functionality when an image is clicked on.

Leave a Reply

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