.NET Zone is brought to you in partnership with:

My name is Lohith G N. I am a Production Engg by education but a Software Engg by profession. I have an industry experience of 10 years in software development. I started with Web Application Development with ASP.NET 1.1 in 2001. Now have expertise in Web Application Development using ASP.NET Web Forms & ASP.NET MVC, Windows Application Development using Win Forms & WPF, Service Oriented Development with WCF. I have been awarded Microsoft Most Valuable Person in Oct 2011 for ASP.NET/IIS area and focus on Open Data Protocol or OData. Lohith is a DZone MVB and is not an employee of DZone and has posted 22 posts at DZone. You can read more from them at their website. View Full User Profile

Detecting OData Service Version

04.19.2012
| 2337 views |
  • submit to reddit

Overview:

Recently, on Apr 9 2012 Microsoft released WCF Data Service 5.0 RTM. As part of this new release there is whole new plethora of features that comes into OData. Here is the official release blog post from the WCF Data Services Team http://blogs.msdn.com/b/astoriateam/archive/2012/04/09/wcf-data-services-5-0-rtm-release.aspx.

What I wanted to do was – to try out the spatial capability that now comes into V3 of OData. I was playing around with a service and wanted to know what service version it is supporting. Thus this blog post so that if anybody else has the same inquisitiveness, read till the end.

OData Service Identification Rules:

Before we actually look at the ways, lets understand some of the Rules which have been defined as part of the protocol itself that makes a Service – OData Service. If you head over to the following URL, complete rules have been posted there: http://services.odata.org/validation/roadmap.htm#rules.

Rules which are in question to detect the OData Service Versions are as follows:

image

As you can see a OData Service must have the DataServiceVersion attribute in the metadata and in an element <edmx:DataServices>. Now that we know the rule, lets see how we can identify the Service Version in various ways.

Ways to check the Version:

I found 4 ways to find version of an OData Service. They are:

  • Looking at the metadata of the OData Service
  • Using Fiddler
  • Using Internet Explorer

We will look at one by one in coming sections.

OData Service Metadata Check:

Every OData Service must describe its Data Model using what is known as Service Metadata Document. The Metadata Document describes its data model in EDM format using XML language for describing models called Conceptual Schema Definition Language (CSDL). The metadata of a OData Service is accessible by appending $metadata to the service root URI. For e.g. Netflix OData Service is found at http://odata.netflix.com/v2/catalog/. So to know the metadata we need to append the $metadata string to the end of the URI i.e. http://odata.netflix.com/v2/catalog/$metadata

So open a browser of your choice and issue a request to http://odata.netflix.com/v2/catalog/$metadata. You will be presented with the metadata. Look out for edmx:DataServices element. It should contain a attribute DataServiceVersion. And that will be the version of the OData Service. Below is a screenshot of the same:

image

Inspecting Response Header Using Fiddler:

In previous section we saw how to find out the Data Service Version using metadata. In this section we will use Fiddler a HTTP debugging tool to inspect the response headers from a Data Service and figure out the version.

- First, open Fiddler and select Composer tab (will be on the right side).
- In the Parsed tab, provide the URL Netflix OData without the $metadata string i.e. type http://odata.netflix.com/v2/catalog/.
- Next click on execute to set the request.
- In the left hand side you will see web sessions and our request will be listed with a status of 200 which means success. Double click on the entry.
- In the right hand side you will see Request and Response Details.
- In the bottom section of the right hand side, select Headers. Those will be the Response Headers.
- If you go through the headers we will see a Response Header by name DataServiceVersion. The value of this header will identify the Data Service Version

Here is a screen shot of the same:

image

image

Inspecting Response Header Using Internet Explorer 9:

Internet Explorer 9 comes with a handy & nifty tools called Developer Tools. This has a new feature which will allow you to capture Network interaction on a web page. So we will make use of this feature and try to figure out the DataServiceVersion response header.

- Open Internet Explorer 9 & navigate to http://odata.netflix.com/v2/Catalog/
- Press F12 to get the developer tools
- Select Network tab & click on start capturing
image
- Refresh the page
- The network interaction from the page will be captured and shown in the grid below
- Double click the entry
- Select tab named “Response Headers”. This will show a Key-Value pairing of all the response headers. You will see DataServiceVersion as one of the key and its value being shown.
image

Conclusion:

In this blog post I try to touch upon the rules that govern a OData Service. The protocol has a clear cut guidelines for OData Producers as to what they should be doing to identify the service as OData Service. There are many rules which needs to be satisfied if you want to call yourself an OData Service. We looked upon one such rule to identify the Data Service Version. Also it was interesting to note the fact that the same version information is also pushed in Response as an Header. For some clients this may be a easy way to track the version.

Hope this post was useful and you learned something new today.

Till next time, as usual, Happy Coding. Code with Passion, Decode with Patience.

Published at DZone with permission of Lohith Nagaraj, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)