Using oData Services in a Windows Phone Application


Windows Phone application developers will be excited to hear that the platform has support for OData - the Open Data Protocol championed by Microsoft. In an earlier article, we learned about the OData Protocol. The CodePlex site for OData provides many client libraries to allow .NET developers to consume oData data services in their applications.

One such library that the Codeplex site offers is the client library for the Windows Phone platform.

This client library can be downloaded from

The client library contains System.Data.Services.Client.dll, System.Data.Services.Design.dll and DataSvcUtil.exe, among other files.

Let us use the client library to create a working Windows Phone application that uses an oData data service.


Let's create an application that lists all of the available languages in which Netflix offers movies.

To begin with, create a data class for the Netflix oData data service.

The URI of Netflix oData data service is

You create the data classes using DataSvcUtil.exe.

datasvcutil /uri: /out:.\Netflix.cs /Version:2.0 /DataServiceCollection 

This will create the Netflix.cs data class.

Now create a new Silverlight for Windows Phone application called WindowsPhoneApplicationODataDemo and add a reference to the System.Data.Services.Client.dll. Also add the Netflix.cs to the project.

Next, modify the MainPage.xaml to add a ListBox, which will display the listings of the languages Netflix offers. The modified xaml will look like this:

<!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="Netflix Offers" 
                        Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Customers" Margin="9,-7,0,0" 
                        Style="{StaticResource PhoneTextTitle1Style}"/>
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding}">
                        <StackPanel Margin="0,0,0,17" Width="432">
                            <TextBlock Text="{Binding Path=Name}" TextWrapping="NoWrap" 
                                       Style="{StaticResource PhoneTextExtraLargeStyle}"/>

Next, create an event handler for the MainPage's PageLoaded event. In this event hander, add the code to create a DataServiceContext and DataServiceCollection object.

Also, in this method, create an eventhandler for the DataServiceCollection's LoadCompleted event.

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            // Initialize the context and the binding collection 
            netflix = new DataServiceContext(netflixUri);
            languages = new DataServiceCollection<Language>(netflix);
            // Register for the LoadCompleted event.
                += new EventHandler<LoadCompletedEventArgs>(languages_LoadCompleted);
            // Load the languages feed by using the URI.

Now, add the code in the languages_LoadCompleted to display the data returned from the data service.

void languages_LoadCompleted(object sender, LoadCompletedEventArgs e)
            if (e.Error == null)
                // Handling for a paged data feed.
                if (languages.Continuation != null)
                    // Automatically load the next page.
                    this.LayoutRoot.DataContext = languages;
                MessageBox.Show(string.Format("error occured"));

Compile and run the application. You will notice that when the DataServiceCollection object is loaded, the application shows all the languages Netflix offers movies in.

The DataServiceCollection object is loaded
Figure 1: The DataServiceCollection object is loaded

If you scroll down, you will find more languages.


In this article, we saw how to create a Windows Phone application which consumes oData data services. Hope this article inspires you to write more data centric applications that utilize oData services.

About the Author

Vipul Vipul Patel

Vipul Patel is a Software Engineer currently working at Microsoft Corporation, working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at



  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date