user2463514
user2463514

Reputation: 273

Querying Odata Service using DataServiceContext get json result which support version 2

I have written my odata service consumer code which supports Odata V3. I have written Logic as mentioned here Consume Odata Service and get result in JSON

The java odata service which I am consuming is written in Odata V2. Now I want to get result as Json what is the approach. Please help.

I have tried following apporaches but I failed to get result: 1. UseJson method of data context but it supports only odata service version 3 or higher. 2. passing header as json but it gives me error.

Upvotes: 0

Views: 1554

Answers (1)

Jen S
Jen S

Reputation: 4555

Unfortunately, if your server does not support v3 of OData, you cannot use the WCF Data Services client with JSON.

You can still use the WCF Data Services client with Atom. Is this acceptable for your scenario?

Alternatively, if you must use the old JSON format, you could use ODataLib (available on NuGet as Microsoft.Data.OData) to read and write verbose JSON payloads. ODataLib is a low-level serialization and deserialization library for OData payloads; you won't get the niceness of the WCF Data Services client library, and you'll have to implement materialization, entity tracking, etc., on your own, but it's a lot better than just using JSON.NET (or a similar library) directly.

My blog, http://odata.jenspinney.com/, has some examples of using ODataLib. If you decide to go this route, feel free to ask questions on how to get specific scenarios working.

Upvotes: 1

Related Questions