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

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds