Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find OData version from metadata

Tags:

rest

odata

I have access to a OData service. Now I need find the OData version of the service. There are version attributes in $metadata. But I don't know which one to pickup.

Do I need to take it from <edmx:Edmx Version="1.0"> or DataServiceVersion or from HTTP Header

For example,

  1. http://services.odata.org/v4/%28S%28cy2mvwlr34teasunjfqlhlyg%29%29/TripPinServiceRW/$metadata returns Version as 4.0 but does not contain DataServiceVersion in the response. But it has OData Version HTTP header

  2. http://services.odata.org/OData/OData.svc/$metadata returns Version as 1.0 and DataServiceVersion as 3.0. This does not contain OData Version HTTP header. But it has DataServiceVersion HTTP header

  3. http://services.odata.org/V3/Northwind/Northwind.svc/$metadata returns Version as 1.0 and DataServiceVersion as 1.0. This does not contain OData Version HTTP header. But it has DataServiceVersion HTTP header

Please let me know how can I find the OData version using service metadata? Or is there any other way to find it?

like image 895
sag Avatar asked Sep 10 '15 11:09

sag


People also ask

How do I know what version of OData I have?

In an Excel workbook, I go to Data > Get Data > From Other Sources > From OData Feed, type the service's URL and click OK. https://services.odata.org/V4/Northwind/Northwind.svc/, so clearly it supports OData 4.

How do I know if my OData is v2 or V4?

Maybe a flow like: Check if <edmx:Edmx /> version is 4.0 (you know OData v4) Else, check if <edmx:DataServices /> has a MaxDataServiceVersion property (you now have highest available OData version) Else, check if <edmx:DataServices /> has a MinDataServiceVersion property (you now have minimum supported OData version)

How do I read OData metadata?

Add /$metadata to the URI in the address bar to view the metadata of the OData service. The metadata document displays the relevant information that the OData service provides for an OData client in a CSDL (Common Schema Definition Language).

What is the latest version of OData?

OData Version 4.01 OData has been standardized by OASIS and approved as an ISO/IEC International Standard. The OASIS OData Technical Committee has published the latest OData 4.01 draft as a Committee Specification.


1 Answers

According to OASIS standard, for each example:

  1. v4 now needs to set Version on the Edmx element

For examples 2 and 3, you'll want to read this note about versioning which states:

The OData protocol supports a versioning scheme for enabling services to expose new features and format versions without breaking compatibility with older clients.

OData requests and responses MAY be versioned according to The DataServiceVersion Header.

An OData client SHOULD use the MinDataServiceVersion and MaxDataServiceVersion headers in order to specify the range of acceptable response DataServiceVersions.

The service SHOULD respond with the maximum version supported by the service that is less than or equal to the specified MaxDataServiceVersion.

You'lll notice things are kind of the wild wild west in terms of OData implementations (a lot of MAY's and SHOULD's. In terms of how the examples above fit this specification:

  1. v2 specifies that the Version must be 1.0, but that the DataServiceVersion must be the version of OData protocol required to consume the service, and be one of ['1.0','2.0','3.0'], per spec.
  2. This service is claiming to support OData clients v1-v3. So a client could submit a request with their own DataServiceVersion of 1.0, 2.0 or 3.0 and still receive a response that fits the standard for the given version.

So, depending on what service you're connecting to, you'll want to check differently. Maybe a flow like:

  1. Check if <edmx:Edmx /> version is 4.0 (you know OData v4)
  2. Else, check if <edmx:DataServices /> has a MaxDataServiceVersion property (you now have highest available OData version)
  3. Else, check if <edmx:DataServices /> has a MinDataServiceVersion property (you now have minimum supported OData version)
  4. Else, check if <edmx:DataServices /> has a DataServiceVersion property (you now have minimum supported OData version)
like image 95
mitch Avatar answered Nov 08 '22 16:11

mitch