Mar 25, 2010

Consuming SharePoint 2010 RESTful service in Silverlight and Data Binding

SharePoint 2010 now provide SOAP based web service, REST, and Client OM, and all of them are out of box. REST is becoming very popular, but not in SharePoint world yet for whatever reasons. One of them I think is, now that Client OM can do it all, why bother REST? Learning curve for client OM will be much shorter for sharepoint developers who are already familiar with server side OM. That has been my thought ever since I first time heard of REST from Paul Stubbs's PDC presentation on using SharePoint RESTful service. Lately I read a blog from Andrew Cornell where he posted a "small challenge" of binding sharepoint list items to Silverlight application. The problem is, Client OM is weakly typed, it doesn't provide properties for list columns. The solution could be to create a converter, or write a wrap class, either way you need to write a quite lot of code and/or learn WPF's converter. My intuition is, using REST can do data binding natively since it is strongly typed.

To prove this concept, i wrote a small Silverlight application which binds data from SharePoint list called AdventureEmployee. xaml looks like this:


Then in Code behind, first add service reference, and define DataService Query:


and then in the AsynCallback:


Those are all code I wrote.(the code can be even simpler: splist.ItemSource=query.EndExecute(result) VStudio created the whole datacontext class. So if you don't like typing, use REST for data binding.

Related post: Consuming SharePoint 2010 RESTful service from Ajax Javascript