So you downloaded the cool new tools for Windows Phone 7 Development and you want to connect to one of those amazing OData feeds… (okay probably just the NetFlix one right now), but perhaps you’ve hit a snag or need a little help getting started..
You need OData client support, so:
- Download the OData client for WP7.
- Run the downloaded file to extract a copy of System.Data.Services.Client.
- Add a reference to the DLL to your project.
- Add an imports/using state for System.Data.Services.Client.
If you are still using the VS2010 RC (which you probably are as of today, as the current WP7 phone CTP is not compatible with the new VS2010 RTM), then you may have had a problem with “Add Service Reference”, specifically that it’s not appearing…
From the release notes:
The Add Service Reference option is not supported in the Windows Phone add-in to Visual Studio 2010. Workaround: Use Visual Studio 2010 Express for Windows Phone to add service references
So you can open up your project with VS 2010 Express for WP, which should also be on your machine. However, if you have a solution with other projects, they may not be supported in the Express SKU… life is getting complicated.
So, you can easily add the reference manually:
- Open the VS2010 command prompt from the Start menu.
- CD to your project directory
- Issue a command similar to: datasvcutil /uri:http://odata.netflix.com/Catalog/ /dataservicecollection /language:CSharp /Version:2.0 /out:NetFlixRef.cs
- Use Add Existing Item to add in the the proxy class (in this case NetFlixRef.cs).
- You then add an imports/using statement for the namespace in the class and off you go…
- Add code similar to this to get started on the binding…
var query = linq query on SomeContainer.SomeEntitySet;
var collection = new DataServiceCollection<SomeProxyEntity>();
someListBox.ItemsSource = collection;
- … and then bind away in your XAML.