Windows Phone WCF OData Client

Windows Phone Tutorial

In a recent posting I showed how to create a quick OData service using Entity-Framework Code-First and SQLCE4.  In this posting I’ll show how to create a simple Windows Phone client to interact with that service.

Begin by creating the client, using the Windows Phone Databound Application template. Once the directory is created, you need to create a proxy for the server.  Open a command window and navigate to the directory for your application. 

Use the latest DataSvcUtil.exe from

Here are the options to use

/uri – This will point to the service URI. In this case, it’s http://localhost:?????/BookDataService.svc

/out – This is the DataServiceContext class that will be generated.

/Version – should be set to 2.0

/DataServiceCollection – Include this flag to generate collections derived from the DataServiceCollection base.

I  ran it as follows:



Add the resulting file (BookDataService.cs) to the project, using Add->Existing. 

Modify the Xaml in your new client application to bind as you would bind to any enumerable source; that is begin by changing the binding on the ItemsSource property of the ListBox from Binding Item to just Binding

Keeping things simple, modify the Binding for LineOne and LineTwo to two of the public properties in your DataService.  Here’s the Xaml I created in the client,

                  Text="{Binding Title}"
                  Style="{StaticResource PhoneTextSubtleStyle}" />
                  Text="{Binding ISBN}"
                  Style="{StaticResource PhoneTextSubtleStyle}" />

Add a member variable to hold the context from the Entity Framework. The db type is Book and the context is BookContext.  Initialize it using the URL of the service,

BookContext context = 
    new BookContext( 
        new Uri( 
            "http://localhost:57361/BookDataService.svc/" ) );

Create a second member variable of type DataServiceCollection<Person>  — note you will need to add a reference to System.Data.Services.Client.  Do not initialize this member until the constructor:

public MainPage()
    books = new DataServiceCollection<Book>( context );
        new Uri( 
            "http://localhost:57361/BookDataService.svc/Books" ) );

Finally, be sure to point the data context to the books collection. 

With this you have a client running against the service you created from  the earlier post.

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen Pluralsight & LinkedIn Learning courses. He was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP and a Microsoft MVP.
This entry was posted in Data, Essentials, Mango, Mini-Tutorial, Patterns & Skills, WindowsPhone and tagged . Bookmark the permalink.

One Response to Windows Phone WCF OData Client

Comments are closed.