Overview of oData Protocol for Windows Phone

Introduction

Windows Phone application developers frequently need to access data to present in their applications. Of the variety of facilities available for data services, Microsoft touts oData as solution, which is based on entity and relationship model that allows access to data in REST style (REST stands for representative transfer).

What is oData?

The documentation for Open Data Protocol defines it as a Web protocol for querying and updating data and builds upon Web technologies to provide information from a variety of applications, services and stores.

Odata provides a client library for the windows phone platform that can generate http requests to the odata data service provider. The library is available for download from odata's codeplex page. The client library transforms the response feed into objects, which can be used by the application.

Where to Get the Client Library?

To get the client library, download the latest version. When you extract the contents, you will find the following files:

DataSvcUtil.exe - tool to generate data classes that represent the data model of an OData service. This tool has a few command-line options which we will discuss later.

Readme.txt - describes the contents of the client library.

System.Data.Services.Client.dll and System.Data.Services.Design.dll - client libraries we will discuss in another article.

If you open up System.Data.Services.Client.dll inside Visual Studio's Object browser, you will notice it contains the following classes:

Open up System.Data.Services.Client.dllB in Visual Studio
Figure 1: Open up System.Data.Services.Client.dll in Visual Studio

The DataServiceContext class helps to abstract the implementation against specific data services and also helps maintain change in state of entities on the client, which helps to support change tracking and identity management.

To start with, when using an OData data service provider, we need to generate data classes for consumption in our application.

We use the datasvcutil.exe for this purpose.

For example, if you were developing a NetFlix application, you can use the datasvcutil to generate the data classes.

datasvcutil /uri:http://odata.netflix.com/v1/Catalog/ /out:.\Netflix.cs /DataServiceCollection

Let us look all the arguments supported by datasvcutil.exe.

/uri: The URI hosting the OData Service.

/out : The name of the data class file you want to generate. This file will represent the data objects.

/DataServiceCollection: This ensures that DataServiceCollection classes are generated for each collection in the model. This facilitates easy binding to UI elements.

/in: The path of the file to read the conceptual model from.

/language: You have an option to generate data classes in either VB or C#. By default, the language is C#.

/help: displays the help text.

DataServiceCollection is a dynamic data collection that provides notifications when collection gets modified.

Using Data Services

All operations against data services in the Windows Phone platform are asynchronous. Also, these operations are performed using Begin/End method pairs. The Begin method lets you register a delegate, which can be called by the operating system. This delegate will then call the End method when invoked.

How oData Queries Work

When an application makes a URI based query against an oData service, the BeginExecute method is called. The client library then creates an HHTP GET request message, which is then fired. When an EndExecute method is called, the client library parses the response message to convert it to data service class instances.

Since OData limits data that a query can return, you can use LoadNextPartialSetAsync to load the next set of data.

Summary

This article presented an overview of the OData Protocol. In a subsequent article we will learn how to develop a Windows Phone application, which consumes an oData service.



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 vipul_d_patel@hotmail.com

Comments

  • http://www.voguebloom.com

    Posted by llzzmm on 06/25/2011 08:15pm

    == http://www.voguebloom.com/ ==== http://www.newfashion4biz.com/ is specialized in online service on ugg Jordan air max oakland raiders $30--39; Ed Hardy AF JUICY POLO Bikini $20; Handbags (Coach lv fendi d&g) $30 T shirts (Polo ,edhardy,lacoste) $15 Jean(True Religion,edhardy,coogi) $30 Sunglasses (Oakey,coach,gucci,Armaini) $15 New era cap $15 Bikini (Ed hardy,polo) $20 ACCEPT PYAPAL PAYMENT AND CREDIT CARDS DELIVERY TO YOU DOOR TO DOOR Welcome to: == http://newfashion4biz.com/ ==== Air jordan(1-24)shoes $33 Handbags(Coach l v f e n d i d&g) $35 Tshirts (ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,A r m a i n i) $16 New era cap $15 Bikini (Ed hardy) $25 FREE sHIPPING,ACCEPT PYAPAL PAYMENT AND CREDIT CARDS DELIVERY TO YOU DOOR TO DOOR. == http://www.newfashion4biz.com/ ====

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

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Is your IT Automation strategy saving you money or just becoming more complex and costly? With the right unified strategy, IT Automation can pay for itself and deliver far more business value. Watch this on-demand webinar, "New Strategies to Manage IT Automation Complexity" and learn how to: Reduce costs by integrating automation for servers, middleware, networks and databases Eliminate manual and tedious IT Operations tasks with both new and existing technology Save time and money by consolidating …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds