I’ve been getting performance results that I cannot explain, when comparing a client that consumes a REST service and a SOAP service. What I did is create a service proxy as follows:
REST:
WebHttpBinding webBinding = new WebHttpBinding();
webBinding.AllowCookies = true;
webBinding.MaxReceivedMessageSize = int.MaxValue;
CustomBinding custom = new CustomBinding(webBinding);
WebMessageEncodingBindingElement webMEBE = custom.Elements.Find<WebMessageEncodingBindingElement>();
webMEBE.ContentTypeMapper = new MyMapper();
webMEBE.ReaderQuotas.MaxArrayLength = int.MaxValue;
var factory = new WebChannelFactory<ITest>(custom, new Uri("http://localhost/Test"));
var proxy = factory.CreateChannel();
SOAP:
endPointAddr = "net.tcp://" + textBox2.Text +
":8909/MyService";
tcpBinding = new NetTcpBinding();
tcpBinding.MaxReceivedMessageSize = int.MaxValue;
tcpBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
tcpBinding.TransactionFlow = false;
tcpBinding.Security.Transport.ProtectionLevel =
System.Net.Security.ProtectionLevel.EncryptAndSign;
tcpBinding.Security.Transport.ClientCredentialType =
TcpClientCredentialType.Windows;
tcpBinding.Security.Mode = SecurityMode.None;
endpointAddress =
new EndpointAddress(endPointAddr);
IService1 proxy =
ChannelFactory<IService1>.CreateChannel(tcpBinding, endpointAddress);
Both IService1 and ITest have one method that I use, GetRequest(), which returns an ~300Kb object. IService1.GetRequest() is an OperationContract, ITest.GetRequest() is a WebGet.
Once I open the channels in both cases I ran a tight loop of proxy.GetRequest(), to figure out how many Requests / s each can handle. The results were that if the test was on a local machine SOAP outperformed REST at 5:1, and over a network SOAP still outperformed REST by about 50%.
I do not understand why there is such a big difference.
The difference is because of the binding you’re using. You’re using
net.tcpas the protocol for your SOAP service, which uses a proprietary binary format for transporting messages. That means that non-WCF technologies won’t be able to connect to your service.WebHttpis being used for the REST service, which is going to be much more compatible with other (non-.NET) technologies, but isn’t going to have the same performance.If you want a better “apples-to-apples” comparison of SOAP vs. REST performance, use a
WsHttpBindingorBasicHttpBindingfor your SOAP service.