netTcpBinding 怎么会比 wsHttpBinding 慢呢?

发布于 2024-09-24 10:58:24 字数 1817 浏览 0 评论 0原文

我已经实现了一个场景,使用 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;
}

I have implemented a scenario which uses netTcpBinding and WsHttpBinding with Transport Security(https) as communication binding type in WCF. Then I compared the performance results. Interestingly, netTcpBinding was slower than wsHttpBinding. I have read a a lot of documents about binding performance and I know that the netTcpBinding provides the fastest communication because of binary encoding.

Can you explain what may cause this situation in my tests? Thanks.

Test environment: 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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脱离于你 2024-10-01 10:58:24

您的 net.tcp 绑定使用身份验证,但 ws http 绑定不使用身份验证。还可以使用来自单个代理的多个操作调用和更大的消息负载来重复您的测试。由于通道创建和连接建立,第一次调用总是很慢。

Your net.tcp binding uses authentication but ws http binding doesn't. Alse repeat your test with several operation calls from single proxy and with bigger message load. First call is always slow because of channel creation and connection establishment.

少女七分熟 2024-10-01 10:58:24

你说的是延迟还是吞吐量。客户端是否创建连接然后立即关闭它,或者是否跨越多个调用。

NetTcp 对相同的连接进行了优化,并且有效负载大小会更小,因为它对 wshttp 使用 BinaryEncoding 与 TextEncoding。

如果您正在查看延迟 - NetTcp 执行 Windows 身份验证会导致 AD 查找,而在 wshttp 上则使用 SSL 身份验证。

Are you talking about latency or throughput. Does a client create a connection and then immediately close it or does it span over multiple calls.

NetTcp has optimization over a same connection and payload size would be smaller since it uses BinaryEncoding vs TextEncoding for wshttp.

If you are looking at latency - NetTcp does windows auth with causes an AD lookup vs on wshttp you are using SSL auth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文