[英]How to make WCF NetTcpBinding working with TLS
我是 WCF 的新手。 我有一个使用 NetTcpBinding 协议的简单 WCF 服务器/客户端 C#(框架 4.8)应用程序。 应用程序向服务器发送一条消息,服务器返回带有日期时间戳的消息。
我需要使应用程序使用 TLS。
服务器:
host = new ServiceHost(typeof(MyService));
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 |
SslProtocols.Tls;
host.AddServiceEndpoint(typeof(IMyService), binding, new Uri("net.tcp://localhost:8888/implementclass"));
host.Open();
客户:
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
EndpointAddress epa = new EndpointAddress($"net.tcp://{txtIPAddress.Text}:8888/implementclass");
ChannelFactory<IMyService> chn = new ChannelFactory<IMyService>(binding, epa);
chn.CreateChannel();
服务合同:
[运营合同]
string Send(string s);
当客户端/服务器在两台不同的计算机上运行(防火墙在两台计算机上都禁用)时,出现以下错误:
服务器已拒绝客户端凭据
客户端/服务器在安装的同一台 PC 上工作。 当我使用不安全的连接时,客户端/服务器也可以工作:
binding.Security.Mode = SecurityMode.None
如何使应用程序使用 TLS 协议工作?
您可以尝试为传输模式设置 ClientCredentialType 属性,以下代码将该属性设置为 Windows。
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType =TcpClientCredentialType.Windows;
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
如何使应用程序使用 TLS 协议工作?
您可以阅读以下文章:
.NET 框架的传输层安全 (TLS) 最佳实践
如何在客户端上启用 TLS 1.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.