I am starting this new thread as a continuation of comments in: Consume Odata Service and get result in JSON
The issue that I am facing is that I have upgraded to wcf data services 5.5 and wcf client tools 5.3 as recommended in the thread. And I am trying to perform a simple post to the following JayStorm service: https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/
I generated the client service reference in .Net and am running 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 without it and with a no parameter UseJson() an exception is thrown because the service is not fully odata v3 compliant. With this approach SaveChanges() still throws an exception but the airport record is actually inserted in to the database and the returned information for the record (from JayStorm), because it contains the old school style root "d" property, causes a parse exception and the exception is thrown in the second part of the SaveChanges().
My question is: Is there anything I can do about this in order to fully complete the post to JayStorm? It seems not as the new wcf client no longer supports the old verbose json (which I think is where the "d" comes from?).
EDIT: Here is the POST raw data from fiddler:
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 raw data from fiddler:
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