我已经实现了一个场景,该场景使用netTcpBinding和WsHttpBinding以及传输安全性(https)作为WCF中的通信绑定类型。然后我比较了性能结果。有趣的是,netTcpBinding比wsHttpBinding慢。我已经阅读了很多关于绑定性能的文档,我知道netTcpBinding因为二进制编码而提供最快的通信。
你能解释一下在我的测试中可能导致这种情况的原因吗?感谢。
测试环境:IIS 7
public static WSHttpBinding GetWSHttpForSSLBinding()
{
WSHttpBinding binding = new WSHttpBinding();
binding.TransactionFlow = true;
binding.MaxReceivedMessageSize = 2147483647;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.CloseTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
return binding;
}
public static NetTcpBinding GetTcpBinding()
{
NetTcpBinding binding = new NetTcpBinding();
binding.TransactionFlow = true;
binding.MaxReceivedMessageSize = 2147483647;
binding.PortSharingEnabled = true;
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
binding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.TripleDesSha256;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.CloseTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
return binding;
}
答案 0 :(得分:3)
您的net.tcp绑定使用身份验证,但http绑定不使用。另外,通过单个代理的多个操作调用以及更大的消息加载来重复测试。由于频道创建和连接建立,第一次呼叫总是很慢。
答案 1 :(得分:2)
您是在谈论延迟还是吞吐量?客户端是创建连接然后立即关闭它还是跨越多个调用。
NetTcp在同一连接上进行优化,有效负载大小会更小,因为它对wshttp使用BinaryEncoding和TextEncoding。
如果您正在考虑延迟 - NetTcp会执行Windows身份验证,导致AD查找与使用SSL身份验证的wshttp相比。