user203687
user203687

Reputation: 7237

How to deserialize JSON returned by WCF Data Service (OData)

An external OData Service returns the following during a POST operation (for a service operation):

{
"d" : {
"__metadata": {
"uri": "http://dd-1620/ServiceData.svc/Customers('1001')", "type": "DataModel.Customer"
}, "MasterCustomerId": "1001", "SubCustomerId": "0", "FirstName": "Jag", "LastName": "Chat"
}
}   

I wrote the following to deserialize the above:

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream respStream = resp.GetResponseStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ReturnType));
ReturnType oRespCus = (ReturnType)ser.ReadObject(respStream);

Now, oRespCus is indeed instantiated. However, with all fields set to null.

Can anyone help me on this.

thanks

Upvotes: 2

Views: 2061

Answers (1)

user203687
user203687

Reputation: 7237

For those who do not know, I would like to share the answer I received from here

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/55b6f018-2944-4160-8393-62a14376c361

thanks all.

Upvotes: 1

Related Questions