Skip to Content
Author's profile photo Debdutt Mondal

Windows Store C# Split application consuming odata.

Below is an example of a simple application for windows mobile 8 consuming OData.

I divided the task into 2 steps
  1. Creating a simple c# split application and understanding how the sample data is getting displayed on screen.
  2. Wiring the application to the reference service to show data fetched from web.

Simple Split Sample App

Under File -> New -> Project selectInstalled -> Templates -> Visual C# -> Windows Store And select Split App(XAML) from the central pane.
Once you click “OK” you have a sample application that will run and show you data! To launch the application hit F5, this launches the application in Debug mode.
On launch of the application you can see the first screen as below
On clicking “Group Title 1” the screen with the list of the item and the details about each item comes up.
Now our task is to find out where the sample data on both these screens came from.  For this look into Solution Explorer -> Solution ‘WinOdata’ -> DataModel -> SampleDataSource.cs
Search for the method SampleDataSource(). This is where all the data is getting added to both the screens. A new SampleDataGroup class is created, to this new SampleDataItem classes are added, and finally the SampleDataGroup is added to AllGroups which is a collection of SampleDataGroup declared just at the beginning of the SampleDataSource class.
I suggest you play a little with this code and keep running your application with each change to get an idea of how each of these changes affect the display of data on the screens.

With this we have finished our first step of creating a simple application and knowing what code we need to change to show our data instead of the sample data.

Creating Reference service and displaying OData.

Now we will create a reference service. For creating a reference service right click on “WinOData” under “Soluton ‘WinOData'” and select “Add Service Reference..”

Fill in as below and click ok.
Namespace: odataService
You can see odataService under Service Reference in Solution Explorer.
Now we will start editing SampleDataSource.cs and wire it to show our data

Add the following line at the top of the class among the other “using” statements.

 using WinOData.odataService;

We will code a new method CategoryProductList(), we will need this new method as we will be firing async queries and for that the method needs to be async and the SampleDataSource() method cannot be made into async.

 async void CategoryProductList()
            DemoService service = new DemoService(new Uri(""));
           // The below code is required if the service expects authentication
             //  service.Credentials = new NetworkCredential("username", "password", "domain");
            var query = from p in service.Categories
                        select p;
            DataServiceQuery<Category> dqs = (DataServiceQuery<Category>)(query);
            TaskFactory<IEnumerable<Category>> tf = new TaskFactory<IEnumerable<Category>>();
            IEnumerable<Category> b = await tf.FromAsync(dqs.BeginExecute(null, null),
                                      iar => dqs.EndExecute(iar));
            foreach (Category cat in b)
                var group1 = new SampleDataGroup("cat"+cat.ID,
                 var oquery = from op in service.Products
                             where op.Category.ID == cat.ID
                            select op;
                 DataServiceQuery<Product> odqs = (DataServiceQuery<Product>)(oquery);
                 TaskFactory<IEnumerable<Product>> otf = new TaskFactory<IEnumerable<Product>>();
                 IEnumerable<Product> ob = await otf.FromAsync(odqs.BeginExecute(null, null),
                                          iar => odqs.EndExecute(iar));
                 foreach (Product products in ob)
                    string description = String.Format("Description:{0}\nPrice:{1}\nRating:{2}\n", products.Description, products.Price, products.Rating);
                    group1.Items.Add(new SampleDataItem("product"+products.ID,
And Finally the SampleDataSource() method will look like below.
 public SampleDataSource()
That’s it! We are done with our application! Hit F5 and see the Application running. You should see something like below.
On clicking Beverages we get the below screen.
  Thus we completed a simple application for windows mobile 8 consuming OData! Hope this helps.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo David Clavey
      David Clavey

      Nice article 🙂

      Author's profile photo Masoud Eb
      Masoud Eb


      Nice , Is that work on windows mobile 6.1?