Unable to parse odada json answers containing root d property using wcf client services 5.3 generator

I start this new thread as a continuation of the comments in: Consume the Odata service and get the result in JSON

The problem I ran into is that I upgraded to wcf data services 5.5 and wcf client tools 5.3, as recommended in the thread. And I'm trying to execute a simple post for the following JayStorm service: https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/

I created a client service link in .Net and run the following code:

using Microsoft.Data.Edm; using Microsoft.Data.Edm.Csdl; using Microsoft.Data.Edm.Validation; using Microsoft.Data.OData; using System; using System.Collections.Generic; using System.Linq; using System.Spatial; using System.Text; using System.Threading.Tasks; using System.Xml; namespace AirportDBDataImporter { class Program { static void Main(string[] args) { var url = "https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/"; var db = new AirportDB.mydatabaseService(new Uri(url)); var xmlTextReader = new XmlTextReader(url+"$metadata"); IEdmModel edmModel = null; IEnumerable<EdmError> errors = null; if (EdmxReader.TryParse(xmlTextReader, out edmModel, out errors)) { } db.Format.UseJson(edmModel); //{"Name":"sfd","Abbrev":"sd","GeoLocation":{"type":"Point","coordinates":[-71.56236648559569,42.451074707889646],"crs":{"properties":{"name":"EPSG:4326"},"type":"name"}}} var airport = new AirportDB.Airport(); airport.Abbrev = "Foo"; airport.Name = "Bar"; airport.GeoLocation = GeographyPoint.Create(51.87796, -176.64603); db.AddToAirport(airport); db.SaveChanges(); //var foo = db.Airport.ToList(); } } } 

The EdmxReader part is necessary because an exception is thrown without it and without the UseJson () parameter, because the service is not fully compatible with odata v3. With this approach, SaveChanges () still throws an exception, but the airport record is actually inserted into the database and the returned information for the record (from JayStorm), since it contains the root property ā€œdā€ of the old school style, it causes a parsing exception and the exception is thrown in second part of SaveChanges ().

My question is: is there anything I can do for this to completely fill out the JayStorm message? It seems not like the new wcf client no longer supports the old verbose json (which, it seems to me, comes from "d"?).

EDIT: Here is the original POST data from the violinist:

 POST https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/Airport HTTP/1.1 DataServiceVersion: 3.0;NetFx MaxDataServiceVersion: 3.0;NetFx Content-Type: application/json;odata=minimalmetadata Accept: application/json;odata=minimalmetadata Accept-Charset: UTF-8 User-Agent: Microsoft ADO.NET Data Services Host: open.jaystack.net Content-Length: 196 Expect: 100-continue {"odata.type":"mydatabase.Airport","Abbrev":"Foo","GeoLocation":{"type":"Point","coordinates":[-176.64603,51.87796],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}},"id":null,"Name":"Bar"} 

Here is the response of the source data from the violinist:

 HTTP/1.1 201 Created Server: nginx/1.4.1 Date: Fri, 21 Jun 2013 15:07:40 GMT Content-Type: application/json;odata=verbose;charset=utf-8;charset=UTF-8 Content-Length: 574 Connection: keep-alive X-Powered-By: Express Access-Control-Allow-Origin: open.jaystack.net Access-Control-Allow-Headers: X-PINGOTHER, Content-Type, MaxDataServiceVersion, DataServiceVersion, Authorization, X-Domain, X-Requested-With Access-Control-Allow-Method: POST Access-Control-Allow-Methods: OPTIONS, GET, HEAD, POST, MERGE, PATCH, DELETE, PUT Access-Control-Allow-Credentials: true location: https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/Airport('NTFjNDZjM2MyMjg1Y2FiNjMzMDAwMDAx') Set-Cookie: connect.sid=s%3AvwHQXjoJQO3VUxJdE2jrQ3ja.A4tG9Bv4XTg1gS5xAVgxMyWXJYrV6DULf3xWvj1Uhq8; Path=/; HttpOnly {"d":{"__metadata":{"type":"mydatabase.Airport","id":"https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/Airport('NTFjNDZjM2MyMjg1Y2FiNjMzMDAwMDAx')","uri":"https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/Airport('NTFjNDZjM2MyMjg1Y2FiNjMzMDAwMDAx')"},"Name":"Bar","Abbrev":"Foo","GeoLocation":{"type":"Point","coordinates":[-176.64603,51.87796],"crs":{"properties":{"name":"EPSG:4326"},"type":"name"}},"id":"NTFjNDZjM2MyMjg1Y2FiNjMzMDAwMDAx"}} 

thanks

0
source share
1 answer

As discussed in the comments on another thread, your server does not support V3 OData, and it also does not seem to fit properly when you request a new JSON format. In the request payload, you say that you only understand application/json;odata=minimalmetadata , but the server ignores the odata=minimalmetadata and answers application/json;odata=verbose .

Do you manage a server? I would see how this can be updated to work with v3 OData.

As already stated, the WCF Data Services Client will not work with Verbose JSON. The problem is not just the "d" wrapper; There are tons of differences between the two formats, and the WCF DS client simply cannot understand the old format (and was never capable).

If at all possible, I highly recommend updating the server. If you cannot upgrade the server, you can still use Atom with the WCF Data Services Client and v2 Server. This will mean more bytes on the wire, but if you reduce the size of the payload on the wire, there are even more reasons for updating the server and using the new JSON format, which is much more eloquent than the old format.

0
source

Source: https://habr.com/ru/post/947086/


All Articles