【发布时间】:2022-01-06 18:18:12
【问题描述】:
我是 WCF 的新手。 我有一个使用 NetTcpBinding 协议的简单 WCF Server/Ciient C# (Framwork 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 协议工作?
【问题讨论】: