Note These steps only work if the maximum protocol version of your service is 3 or higher. OData version 3 introduced the new JSON format, and the WCF Data Services client only supports this JSON format. (Old JSON downloads have things like "__metadata" at the top and "d":{...} . In the new JSON format, you'll see things like "odata.metadata" , "odata.type" , etc. .)
First, make sure that you have version 5.1 or more from the WCF Data Sevrices client library (Visual Studio comes with an older version) and an updated version of the toolkit that makes the Add Service Link link in Visual Studio.
You can download the latest version of the tool installer here: http://www.microsoft.com/en-us/download/details.aspx?id=35840 .
Once you have installed this, I recommend upgrading to the latest version of the WCF Data Services client by issuing the following command in the NuGet package manager console:
Install-Package Microsoft.Data.Services.Client
Once you have upgraded to the latest client library, you can use JSON on the client without any problems. Right-click on your project in Visual Studio, select Add Service Link and enter the URL of the service metadata document. In version 5.1 and higher, this will lead to a complete service model, which is necessary to support JSON.
A βadd service linkβ will automatically generate a subclass of DataServiceContext . (You can see this generated code by selecting "Show all files" in the Visual Studio solution explorer and expanding the code behind the service link.) For example, when I do "Add service link" in http://services.odata.org/V3/OData/OData.svc/$metadata , the client library generates a class called DemoService . Use this derived class instead of the DataServiceContext directly, and you can simply call .Format.UseJson() . For instance:
var context = new DemoService(new Uri("http://services.odata.org/V3/OData/OData.svc"); context.Format.UseJson();
source share