C#WCF REST - 如何使用,而不是默认的DataContractSerializer JSON.Net序列化? [英] C# WCF REST - How do you use JSON.Net serializer instead of the default DataContractSerializer?

查看:262
本文介绍了C#WCF REST - 如何使用,而不是默认的DataContractSerializer JSON.Net序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET 3.5中,是否有可能替代默认DataContractJsonSerializer并使用JSON.net序列化呢?

In .NET 3.5, Is it possible to override the default DataContractJsonSerializer and use the JSON.net serializer instead?

注意:我们不希望在类中使用的属性。

NOTE: We do not want to use attributes on the class

推荐答案

是的,这是可以这样做。但是,这不是太简单了。你需要它使用JSON.NET序列化,而不是默认的一个操作参数和需要的WCF栈消息对象之间进行转换的一个新的消息格式。在邮政<一href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx" rel="nofollow">http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx有一个正是这么做的一个例子。在code是4.0编写,但它应该为3.5正常工作。

Yes, it's possible to do so. But it's not too simple. You'll need a new message formatter which uses the JSON.NET serializer instead of the default one to convert between the operation parameters and the message object needed by the WCF stack. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx has an example that does exactly that. The code is written for 4.0, but it should work for 3.5 as well.

这篇关于C#WCF REST - 如何使用,而不是默认的DataContractSerializer JSON.Net序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆