2

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Nice article, but how would you handle XML requests?
Yes, but you'd need to change the WebContentTypeMapper implementation to only return "raw" for JSON requests. The formatter would then be changed to first check the request format (via the WebBodyFormatMessageProperty); if it's XML (or not Raw), delegate the call to the original formatter, which can handle XML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.