So the shiny new Visual Studio 2010 released yesterday and the final Silverlight 4 releases in 2 days.
What if you are still using Visual Studio 2008 and Silverlight 3 and you want to consume all the latest OData goodness?
Background on OData
You know what OData is right?
Well first there was ADO.NET Data Services which provides production and consumption of data via a RESTful architecture using HTTP verbs to perform CRUD-like operations. Client ‘consumer’ and server ‘producer’ classes where included in .NET 3.5 SP1 and client classes where included in Silverlight 3, under System.Data.Services.Client in both cases.
OData at http://odata.org is the evolution of that in the form of a full-on open protocol standard that Microsoft has ‘put out there’ for querying and updating data based on extensions to AtomPub. Products such as SQL Azure, SharePoint 2010, SQL Server 2008 R2 Reporting Services and Windows Azure Table Storage will expose OData-accessible data and there a growing number of SDKs available on both ends of the communication channel.
For .NET 4.0, ADO.NET Data Services evolves into WCF Data Services (built on WCF) and the associated classes support the OData protocol. Silverlight 4 will also have WCF Data Services supporting OData.
For .NET 3.5 SP1, the Data Services Update for .NET 3.5 SP1 was made available as a full release. For Silverlight 3, only a CTP release is available – the ADO.NET Data Services for Silverlight 3 Update CTP3 (eat your heart out long-name marketing folks).
I installed VS2010 yesterday which installed the SL3 toolset (given that SL4 tools don’t come until this Thursday). I thought it would be good to explain a few things for people that are still using Silverlight 3.
To do anything, you need some OData-accessible data. Right now, you can go to the Netflix public catalog at http://odata.netflix.com/catalog and just start exploring the data by tinkering with the URL, following the examples at http://www.odata.org/developers/protocols/uri-conventions.
OData repositories appear to have a version of 2 and cannot be accessed properly from “V1” ADO.NET Services Clients – you need the WCF Services (OData-compatible) client.
Getting OData Client support in your Silverlight 3 application in VS2008
So for those using Silverlight 3 in VS2008 you can give OData a fairly solid go by downloading that CTP.
To use the update OData friendly libraries, you need to:
- Extract the System.Data.Services.Client.dll file to somewhere you remember.
- Add System.Data.Services.Client as a normal reference to your application.
- Go to the project properties, select the References tab, go into Reference Paths, add the directory that you put your extracted class in to. As you come out of there, you should see your new path listed for System.Data.Services.Client.
You can now write OData-friendly client code for Silverlight 3 in VS 2008.
One of the great new classes is DataServiceCollection. It enables fully bound updateable observable collection behaviour so you can bind something like a DataGrid to an OData service (with it’s CRUD-like operations). Think about that🙂
Using DataServiceCollection requires that the objects you pass in, support INotifyPropertyChanged interface.
In a Silverilght 3 app in VS2008 (and even VS2010), the Add Service Reference tool (which apparently runs DataSvcUtil.exe from the V3 framework) does not support adding this when it creates the service client proxy.
The .NET 4 version of this tool does do this work for you, so you may want to installed the 4.0 framework and use it like this to get fully-functional binding classes you can use with DataServiceCollection.
%windir%\Microsoft.NET\Framework\v4.0.30319\DataSvcUtil.exe /dataservicecollection /version:2.0 /language:CSharp /out:myproxyclass.vb /uri:http://odata