LP Pinsonneault blog's

Windows 8, Windows Phone, ...


Building a Windows Phone 7 application: Part 1 - Accessing the data

imageA 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.


2010-07-04 10h20_07

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 .

 Note: 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.

imageCurrently, 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

public TechDaysProxy()
ODataContext =
new Xrm.XrmDataContext(
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>();

collectionVenues.LoadCompleted +=
new EventHandler<LoadCompletedEventArgs>(collectionVenues_LoadCompleted);
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")
select v;
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.
2010-06-12 22h55_042010-06-12 22h06_182010-06-12 22h07_36
2010-06-12 22h07_592010-06-12 22h08_242010-07-04 12h50_25



PART 2: Implementing the UI

Comments (4) -


Have you had a chance to try the latest Beta tools release? I wonder if the issue you mentioned with the assemblies is gone...


I've migrated to the Beta, but i didn't had the time yet to test if the issue with signed assembly is now fixed. I give it a try and it work well. So there is no need to fix the assembly anymore.



Tyson F. Gautreaux
Tyson F. Gautreaux

Between me and my husband we've owned more MP3 players over the years than I can count, including Sansas, iRivers, iPods (classic & touch), the Ibiza Rhapsody, etc. But, the last few years I've settled down to one line of players. Why? Because I was happy to discover how well-designed and fun to use the underappreciated (and widely mocked) Zunes are.


Steam Wallet Hack
United States Steam Wallet Hack

After checking out a few of the blog posts on your blog, I seriously like your way of writing a blog. I book-marked it to my bookmark webpage list and will be checking back in the near future. Take a look at my website as well and let me know how you feel.


Pingbacks and trackbacks (2)+

Add comment

  • Comment
  • Preview