Jayesh
Jayesh

Reputation: 3951

WCF - SOAP or JSON

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

Thanks

Upvotes: 1

Views: 3993

Answers (2)

krisragh MSFT
krisragh MSFT

Reputation: 1918

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!

Upvotes: 1

airbai
airbai

Reputation: 3966

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)

Upvotes: 2

Related Questions