Performance Comparison: SOAP vs. JSON (WCF-Implementation)

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

As you probably know the JSON is more compact format than SOAP, which is very usable when you want to reduce the traffic on the network. To illustrate this, assume there is a class called Airport which looks like shown below:

image

When this class is serialized by using of DataContractSerializer the result is:

<a:Airport><a:Contacts><a:Contact><a:FirstName>huso</a:FirstName><a:LastName>djimbilic</a:LastName></a:Contact>
<a:Contact><a:FirstName>haso</a:FirstName><a:LastName>zgembic</a:LastName></a:Contact></a:Contacts ></a:Contact></a:Contacts><a:Latitude>-161.837997</a:Latitude><a:Longitude>60.779778</a:Longitude><a:Name>PABE</a:Name></a:Airport>

When using REST based service with JSON serialization (DataContractJsonSerializer) the instance of the airport-class sent over the network would look like:
{"Contacts":[{"FirstName":"huso","LastName":"djimbilic"},{"FirstName":"haso","LastName":"zgembic"}],"Latitude":87.652778,"Longitude":34.691111,"Name":"5AL5"}.

My intension is not to describe in detail differences between this two formats, but it is obvious, that the JSON is much compacter.

When we now this, it reasonable to expect that the time needed for consuming of SOAP messages in comparison to JSON messages correlate to the amount of data. If you think this, you are wrong :)

Clearly it means: SOAP transmits 20-40% more data than JSON, but it is (in WCF) faster approximately 20-25% than JSON. How this is possible?  The reason is in WCF-JSON implementation itself. WCF internally serializes JSON streams to some kind of XML-Infoset wire format that requires about 50% more bytes than DataContractSerializer.

Comparison by time

Following diagram shows comparison between JSON and SOAP messaging in ten successively repeated tests. Values
in diagram are given in seconds for 3000 repeats per test. For example the first sample for JSON has taken 14 seconds and 10 seconds for SOAP each 3000 repeats. One repeat means send one request and receive response.
In this specific test we retrieved 101 instances of the class Airport (see below XML description of this type).

image

Exact values in seconds measured in this test ar given in the next table:

JSON SOAP
14 10
17 11
15 12
16 13
17 14
18 14
19 15
20 16
20 17
22 18

 

Comparison by network traffic

JSON (15862 bytes)

Request

GET /GetJsonCoordinates.svc/GetCoordinates HTTP/1.1

Content-Type: application/xml; charset=utf-8

VsDebuggerCausalityData: uIDPo3f2jA1vh9tDhVf/HkaioegAAAAAjmFHoP+8OkyjmjyXSmDL4rwAh+pBIIdPmQ0493uxJYcACQAA

Host: dado-nb0:81

Connection: Keep-Alive

Response

HTTP/1.1 200 OK

Content-Type: application/json; charset=utf-8

Server: Microsoft-IIS/7.0

X-Powered-By: ASP.NET

Date: Fri, 26 Dec 2008 23:13:23 GMT

Content-Length: 15852

 

[{"Contacts":[{"FirstName":"huso","LastName":"djimbilic"},{"FirstName":"haso","LastName":"zgembic"}],"Latitude":87.652778,"Longitude":34.691111,"Name":"5AL5"},{"Contacts":[{"FirstName":"damir","LastName":"dobric"},{"FirstName":"alvin","LastName":"dobric"}],"Latitude":-85.468,"Longitude":32.220147,"Name":"AL05"},{"Contacts":[{"FirstName":"damir","LastName":"dobric"},{"FirstName":"alvin","LastName":"dobric"}],"Latitude":-86.124964,"Longitude":32.358472,"Name":"AL12"}:"dobric"},{"FirstName":"alvin","LastName":"dobric"}],"Latitude":-161.837997,"Longitude":60.779778,"Name":"PABE"}]

 Note: Response not complete!

SOAP (31872 bytes)

Request

POST /GetSoapCoordinates.svc HTTP/1.1

Content-Type: text/xml; charset=utf-8

VsDebuggerCausalityData: uIDPo3j2jA1vh9tDhVf/HkaioegAAAAAjmFHoP+8OkyjmjyXSmDL4rwAh+pBIIdPmQ0493uxJYcACQAA

SOAPAction: "http://tempuri.org/ISoapGpsService/GetCoordinates"

Host: dado-nb0:81

Content-Length: 203

Expect: 100-continue

Connection: Keep-Alive

 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetCoordinates xmlns="http://tempuri.org/"><area>GER</area><numOfRecords>100</numOfRecords></GetCoordinates></s:Body></s:Envelope>

Response

HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8

Server: Microsoft-IIS/7.0

X-Powered-By: ASP.NET

Date: Fri, 26 Dec 2008 23:15:44 GMT

Content-Length: 31872

 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetCoordinatesResponse xmlns="http://tempuri.org/"><GetCoordinatesResult xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.ServiceModel.Samples.BasicSyndication" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Airport><a:Contacts><a:Contact><a:FirstName>huso</a:FirstName><a:LastName>djimbilic</a:LastName></a:Contact><a:Contact><a:FirstName>haso</a:FirstName><a:LastName>zgembic</a:LastName></a:Contact></a:Contacts ></a:Contact></a:Contacts><a:Latitude>-161.837997</a:Latitude><a:Longitude>60.779778</a:Longitude><a:Name>PABE</a:Name></a:Airport></GetCoordinatesResult></GetCoordinatesResponse></s:Body></s:Envelope>

Note: Response not complete!


Posted Dec 27 2008, 03:49 PM by Damir Dobric
Filed under:

Comments

AS wrote re: Performance Comparison: SOAP vs. JSON (WCF-Implementation)
on 05-05-2009 6:58

interesting- does this mean that even though Json can be lightweight - using it with WCF - its actually going to be slower ?

Damir Dobric wrote re: Performance Comparison: SOAP vs. JSON (WCF-Implementation)
on 05-05-2009 9:47

Actually your statement is true. Personaly I think this might be changed in the near future.

geff zhang wrote JSON 和 JSONP
on 12-13-2009 13:43

浏览器安全模型规定,XMLHttpRequest、框架(frame)等只能在一个域中通信。从安全角度考虑,这个规定很合理;但是,也确实给分布式(面向服务、混搭等等本周提到的概念)Web开发带来了麻烦。...

王洋洋 wrote re: Performance Comparison: SOAP vs. JSON (WCF-Implementation)
on 02-07-2010 9:26

nice,不过在我们的开发中一般与很多异构的系统交互,SOAP消息已经成为一个行业规范。

Shirley wrote re: Performance Comparison: SOAP vs. JSON (WCF-Implementation)
on 05-11-2010 18:39

This is hardly a valid comparison between JSON and SOAP.

What the data really says is that WCF is even worse on JSON than it is on SOAP.

Does making anything look this bad and/or work this poorly indicate lack of skill or questionable goals. (WCF, *not* the author)

manish wrote re: Performance Comparison: SOAP vs. JSON (WCF-Implementation)
on 07-01-2010 9:07

now I am  really confused!

anoynymous wrote re: Performance Comparison: SOAP vs. JSON (WCF-Implementation)
on 07-02-2011 21:55

how about compression?

developers.de is a .Net Community Blog powered by daenet GmbH.