當比較使用REST服務和SOAP服務的客戶端時,我得到的性能結果無法解釋。我所做的是創建一個服務代理如下:REST服務代理與WCF SOAP代理的性能
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);
兩個IService1
和ITest
有一個方法,我使用,GetRequest()
,它返回一個〜 300Kb的對象。 IService1.GetRequest()是一個OperationContract,ITest.GetRequest()是一個WebGet。
一旦我在這兩種情況下打開通道,我運行了一個緊密的proxy.GetRequest()循環,以確定每個請求可以處理多少個請求。結果是,如果測試在本地機器上以5:1的速度超過REST,並且通過網絡,SOAP仍然比REST高出約50%。
我不明白爲什麼會有這麼大的差異。
您的SOAP不是SOAP。 – 2012-03-19 16:49:59
尷尬:S。星期五,這是我第一次使用這兩種技術之一,並且從我在搜索WCF SOAP時發現的一個教程中獲益。 – user472875 2012-03-19 16:57:10