1

Are there any performance benefits in using JSON over SOAP to encode messages while working with WCF?

Thanks

Jayesh
  • 3,891
  • 11
  • 55
  • 83

2 Answers2

2

JSON is better than SOAP. JSON has less format infomation than SOAP.

SOAP transmits 20-40% more data than JSON, but it is (in WCF) faster approximately 20-25% than JSON. Please refer to Performance Comparison: SOAP vs. JSON (WCF-Implementation)

airbai
  • 3,906
  • 5
  • 26
  • 30
  • I have a situation where in WCF communicates with a client near real-time. My client polls the service every 4 seconds. The data that is communicated is approximately 10kb big. What would you recommend me in this scenario, SOAP or JSON? Thanks – Jayesh Apr 06 '11 at 06:38
  • 1
    @Joy: Both SOAP and JSON will do the job. There are obviously trade-offs with each one. Go with your gut instinct and you probably won't need to change it. If you do need to change it (maybe to do with bandwidth or processing speed) it's easy. – Greg Sansom Apr 06 '11 at 07:43
  • Well, does this statement remains true until today? – Iúri dos Anjos Sep 14 '17 at 20:08
1

I disagree strongly -- WCF JSON is generally slower than WCF SOAP Binary. Wire size is just one component of serialization and deserialization efficiency. THe other big component is processing time.

Internally, DataContractJsonSerializer maps JSON name/value pairs to an XML infoset. In fact, DataContractJsonSerializer is built on top of the XML-based DataContractSerializer and processes every JSON input and JSON output as if it were dealing with XML. There is a higher-level abstraction layer (a JSON writer and a JSON reader, as exposed via JsonReaderWriterFactory) that actually translates this XML to JSON and JSON back to internal XML.

All this extra translations back and forth between XML infosets and JSON adds up. Don't be deceived by size alone. See this excellent overview (Mapping Between JSON and XML) to see what happens to DataContractJsonSerializer internally and how it pulls all this off.

Now, it may very well be the case that in your scenario, JSON is indeed faster than WCF. But that would be a result of the particular data types you're using, and the particular scenarios you're calling those data types in. You MUST measure your own data sets -- don't read random advice on the internet about perf, including mine. Trust your own numbers!

krisragh MSFT
  • 1,908
  • 1
  • 13
  • 22
  • 3
    Leave it to Microsoft to write a JSON deserializer that is built using an XML parser.. WTF? – ColinM Feb 14 '13 at 05:26