Deserializing JSON in WCF throws xml errors in .Net 4.0
Posted
by Syg
on Stack Overflow
See other posts from Stack Overflow
or by Syg
Published on 2010-05-14T11:08:28Z
Indexed on
2010/05/14
11:14 UTC
Read the original article
Hit count: 324
Hi there. I'm going slidely mad over here, maybe someone else can figure out what's going on here. I have a WCF service exposing a function using webinvoke, like so:
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "registertokenpost"
)]
void RegisterDeviceTokenForYoumiePost(test token);
The datacontract for the test class looks like this:
[DataContract(Namespace="Zooma.Test", Name="test", IsReference=true)]
public class test
{
string waarde;
[DataMember(Name="waarde", Order=0)]
public string Waarde
{
get { return waarde; }
set { waarde = value; }
}
}
When sending the following json message to the service, { "test": { "waarde": "bla" } }
the trace log gives me errors (below). I have tried this with just a string instead of the datatype (void RegisterDeviceTokenForYoumiePost(string token); ) but i get the same error. All help is appreciated, can't figure it out. It looks like it's creating invalid xml from the json message, but i'm not doing any custom serialization here.
The formatter threw an exception while trying to deserialize the message: Error in
deserializing body of request message for operation 'RegisterDeviceTokenForYoumiePost'.
Unexpected end of file. **Following elements are not closed**: waarde, test, root.</Message><StackTrace>
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message,
Object[] parameters)
© Stack Overflow or respective owner