A couple of week ago, the Microsoft TechDays Canada team have publish all data using ODATA. So i said to my self this will be a good hand-on for creating a WP7 application and exploring ODATA at the same time. So I've started to build an application while exploring most of the current feature available.
First i started to look at the data structure of the TechDays.ca ODATA. The object available are Events, Schedules, Speakers, Speaker Tags, Tags, Tracks, Venues, Annotations. So there is plenty of information to build a pretty advance application. I’ve started with the Venue because most of the data are related with the Venue which are the city where the TechDays will stop. So I've just create a simple list of button to which will allow me to access the information related to the selected Venue.
Accessing the data
The first thing to do (after the creation of the Project in Visual Studio) is to create the proxy class the will interface the WCF Data Services and the ODATA format. Currently we cannot add Service Reference using Visual Studio for Windows Phone 7 project. I hope this will be added in a future version. So for now you need to create that class manually by executing the DataSvcUtil.exe in command line:
DataSvcutil.exe /uri:http://www.techdays.ca/OData.svc /DataServiceCollection /Version:2.0 /out:TechDaysODataType.cs.cs
So you can now import that class in your project. But if you try to compile it will fail because you are missing a reference. You need to import the System.Data.Services.Client.dll .
There is currently an issue with the Windows Phone Toolkit April CTP with some Authenticode signed assemblies so i had to fix the System.Data.Services.Client.dll to be able to work with WCF Data Services. Tim Heuer post an article with the instruction on how to fix the affected assemblies : http://timheuer.com/.../windows-phone-tools-update-april-2010-silverlight-xna.aspx
This issue is now fixed in the current beta release.
Currently, I’ve created a library to handle the data. I created an helper that simplify the data query inside the Windows Phone application. This eliminate a lot of code that can often be duplicate. So in the constructor of my helper class TechDaysProxy.cs i instantiate the WCF Data Services client
new Uri("http://www.techdays.ca/OData.svc/", UriKind.Absolute));
CurrentLanguage = LanguageType.English;
Once we have access to the data context we can query the data. So with WCF Data Services which is in this case an implementation of REST. Every query Linq are converted to REST query. If we want to query the object adx_venues we can do it this way:
public void GetVenuesAsync()
var Venues = from v in ODataContext.adx_venues select v;
collectionVenues = new DataServiceCollection<Xrm.adx_venue>();
This will return the a collection of adx_venues. By default, none of the child element will be loaded. So there is 2 ways to load child element. You can modify the LINQ query to add the Expand keywork to include a child table in the result. This may simplify the process but in some case it can increase the delay of getting the information back from the server.
var Venues = from v in ODataContext.adx_venues.Expand("adx_eventspeaker_venue")
The other way, is to get load the information asynchronously. So when we get the data back we load dynamically the child table so we can start displaying some information while the remaining still in process of loading.
void collectionVenues_LoadCompleted(object sender, LoadCompletedEventArgs e)
foreach (Xrm.adx_venue v in collectionVenues)
None of those method are better. You need to apply the proper one base on the context of your application.
This is simple for any other object you may implement the same logic. So there is not much code to implement here.
PART 2: Implementing the UI