How to tweak default JSON serializer in WCF REST

柔情痞子 提交于 2019-12-06 05:07:56

问题


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?


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/6605582/how-to-tweak-default-json-serializer-in-wcf-rest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!