Detecting OData Service Version
Join the DZone community and get the full member experience.Join For Free
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:
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 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:
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:
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
- press f12 to get the developer tools
- select network tab & click on start capturing
- 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.
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.
Opinions expressed by DZone contributors are their own.