8

Is there any way to replace the WCF service application built-in JavascriptSerializer with Newtonsoft Json.Net json serializer?

Frode Evensen
  • 446
  • 1
  • 11
  • 21
iNc0ming
  • 373
  • 1
  • 4
  • 16

1 Answers1

16

WCF doesn't use JavascriptSerializer. It uses DataContractJsonSerializer. And yes, you can replace it with Json.NET by writing a custom message formatter as exemplified in the following blog post.

Igor Lyadov
  • 115
  • 5
Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902
  • 2
    because DataContractJsonSerializer is much slower than Json.NET. – iNc0ming Jun 22 '12 at 11:03
  • Is this a question that you are asking? Is there something else you would like to ask? – Darin Dimitrov Jun 22 '12 at 11:59
  • ok, the question is going further now. According to this article - http://code.msdn.microsoft.com/windowsdesktop/Supporting-different-data-b0351c9a, I have made a custom DispatchFormatter, but how to register it to the wcf service application via web.config? – iNc0ming Jun 22 '12 at 12:33
  • You could write a custom `IServiceBehavior` to apply the message formatter globally to the service. – Darin Dimitrov Jun 22 '12 at 12:53
  • By following this article - [link](http://stackoverflow.com/questions/8082231/custom-behavior-wont-register-in-my-web-config), all works now, thank u guys for help. – iNc0ming Jun 22 '12 at 13:34