How to tweak default JSON serializer in WCF REST

2020-07-18 05:43发布

WCF REST service works great in a way that it will reply/accept JSON or XML depending on header.

I want to tweak built-in JSON serializer a little so it encodes/decodes Byte[] little different. More specifically, I want to use Base64 for that.

Is that any pointers/samples where I can set custom type serializer that will affect whole service?

2条回答
迷人小祖宗
2楼-- · 2020-07-18 06:30

I just succeeded swapping out the default DataContractJsonSerializer with JSON.NET serializer in my WCF REST services 4.0 using NETFx Json.NET MediaTypeFormatter . Also see JSON.NET Serializer for WCF REST Services for the solution to a problem I ran into to get this working.

查看更多
狗以群分
3楼-- · 2020-07-18 06:39

The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx shows how to replace the default JSON serializer (DataContractJsonSerializer) with a custom one (in this case, JSON.NET).

查看更多
登录 后发表回答