Reputation: 53
I have a question about serialization with JSON.NET and working with a WCF REST webservice.
My device which runs the .NET compact framework and has limited feature support uses JSON.NET for serialization/deserialization. Communication via HttpWebRequest to simple WCF REST webservice with parameters like strings or simple classes work like a charm.
Now i have to transmit a collection of key value pairs
List<KeyValuePair<int, object>>
The result of serializing a collection with one element containing a Guid as value looks like this:
[
{
"Key": 52120,
"Value": "180047f8-2ee5-41bb-8da1-68bd94178d79"
},
]
I think that is correct json formatting but if i look at my WCF service it requires me to send the data like:
[{
"key":2147483647,
"value":{
"KeyValuePairOfintanyType":{
"key":2147483647,
"value":{
"KeyValuePairOfintanyType":null
}
}
}
}]
Sending the data serialized by JSON.NET results in connection abort. Does anyone have an idea how to serialize the generic List to fit the requirements of the WCF service? Is there a way to tell JSON.NET to insert those KeyValuePairOf... format?
Upvotes: 2
Views: 455
Reputation: 13460
use DataContractJsonSerializer
wcf use it for rest and they are full compatible
Upvotes: 1