简体   繁体   English

REST服务代理与WCF SOAP代理的性能

[英]Performance of a REST service proxy vs WCF SOAP proxy

I've been getting performance results that I cannot explain, when comparing a client that consumes a REST service and a SOAP service. 在比较使用REST服务和SOAP服务的客户端时,我一直在获得无法解释的性能结果。 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. IService1ITest都有一个我使用的方法GetRequest() ,它返回一个〜300Kb对象。 IService1.GetRequest() is an OperationContract, ITest.GetRequest() is a WebGet. IService1.GetRequest()是一个OperationContract,ITest.GetRequest()是一个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. 在两种情况下打开通道后,我都会运行一个紧密的proxy.GetRequest()循环,以找出每个请求可以处理多少个请求。 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%. 结果是,如果在本地计算机上进行测试,则SOAP的性能要比REST好5:1,而在网络上,SOAP的性能仍然要比REST好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.tcp as the protocol for your SOAP service, which uses a proprietary binary format for transporting messages. 您正在使用net.tcp作为SOAP服务的协议,该协议使用专有的二进制格式来传输消息。 That means that non-WCF technologies won't be able to connect to your service. 这意味着非WCF技术将无法连接到您的服务。 WebHttp is 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. WebHttp用于REST服务,它将与其他(非.NET)技术更加兼容,但不会具有相同的性能。

If you want a better "apples-to-apples" comparison of SOAP vs. REST performance, use a WsHttpBinding or BasicHttpBinding for your SOAP service. 如果要对SOAP性能与REST性能进行更好的比较,请为您的SOAP服务使用WsHttpBindingBasicHttpBinding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM