开发者

Deserializing JSON in WCF throws xml errors in .Net 4.0

I'm going slidely mad over here, maybe someone can help me figure out what's going on. 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)


The service expects { "token": { "waarde": "bla" } }, not { "test": { "waarde": "bla" } }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜