WCF服务+客户端(TLS1.2问题)

WCF Service + Client (TLS1.2 Issue)

我们的服务器已禁用 SSLv3、TLS1.0 和 TLS1.1。因此,Visual Studio 在尝试检索 WSDL 时尝试添加服务引用失败。

"The underlying connection was closed: An unexpected error occurred on a send. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. An existing connection was forcibly closed by the remote host Metadata contains a reference that cannot be resolved: An error occurred while making the HTTP request to https://mywebsite.com/Service/Service.svc?wsdl. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. The underlying connection was closed: An unexpected error occurred on a send. Authentication failed because the remote party has closed the transport stream. If the service is defined in the current solution, try building the solution and adding the service reference again."

WSDL 可在浏览器中访问。当启用 TLS 1.0/1.1 和 SSLv3 时,WSDL 下载正常。但是,由于 PCI 要求,我们必须禁用 SSLV3、TLS1.0 和 TLS1.1。

我知道以下内容 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 但不太确定这是否会出现在连接的控制台客户端或 WCF 服务(或两者)中。

如有任何建议,我们将不胜感激

下一行需要在客户端中,因为这是建立连接的原因。

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

根据此博客 TLS 1.2 and .NET Support: How to Avoid Connection Errors,以上内容适用于 .Net 4.5

对于 .Net 4.6 及更高版本,它将默认为 TLS 1.2,您无需指定 TLS 1.2

对于 .Net 4.0,您需要以下内容。

 System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

NET 3.5 或更低版本,您需要为您的 OS(在博客中列出)安装适当的 Microsoft 补丁。