In this article we are going to see how to consume a OData Service in a Windows Phone application, OData is is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today. ODATA service allows the consumers to query the data over the http protocol and retrieve the result in a plain XML format. Normally a mobile application development requires data that are available as a service which can be consumed and use on demand, where the ODATA Service plays a major role. We have variety of ODATA services that are available in market, rather we can create our ODATA service which can also be consumes as a WCF Data Services. Let us see the step by step process on how to consume the ODATA Service in our Windows Phone application and see how to make use of it efficiently.
Open Visual Studio 2010 IDE in administrator mode and create a new project for Windows Phone with a valid project name as shown in the screen below.
Now we need to design our XAML page where we want to show our consumed ODATA service, we can use any of the listing control to display the data as per our requirement. Let us concentrate on how to consume the OData rather concentrating on how to display the data. Let us try to consume the service of the Telerik Video, as the ODATA service is available using the URI http://tv.telerik.com/services/odata.svc/. To add the ODATA service right click on the project name and select Add Service Reference as shown in the screen below.
Let us provide the OATA Service uri and click on Go button to discover the service online. Once the service is discovered we need to change the namespace to a user defined name as ODataTelerik as shown in the screen below.
On successfully adding the ODATA service reference to the project we can see a list of files added to the service reference folder. Now we are ready with the service, our next step is write some code that will do the necessary process to get the data from the service and show it to the user interface which we designed. Add the below 2 namespaces which are required to consume and get the data from the ODATA service as shown in the screen below.
Once we added the above 2 namespaces we need to start with our code to consume the service and use is across to get the data and showcase in any format that takes care of the requirement.