作者:再生Solo_868 | 来源:互联网 | 2024-12-12 11:54
我在尝试通过basicHttpBinding与Web服务通信时遇到了问题,具体实现如下:
EXCClient CreateClient() { var binding = new System.ServiceModel.BasicHttpsBinding(); binding.ReaderQuotas.MaxArrayLength = int.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; binding.UseDefaultWebProxy = false; var endpoint = new System.ServiceModel.EndpointAddress("https://{siteName}/{service}"); var client = new EXCClient(binding, endpoint); return client; }
该服务部署在IIS 7.5上,服务器上托管了多个站点。调用此服务的.NET表单站点代码如下:
var x = service.Client.GetResults({parameter});
当服务运行约15分钟后,开始出现以下错误:
An error occurred while making the HTTP request to https://{siteName}/{service}/. This could be due to the server's certificate not being correctly configured with HTTP.SYS for HTTPS, or a mismatch in the security binding between the client and the server. The underlying connection was closed: An unexpected error occurred on a send. —> System.IO.IOException: The handshake failed due to an unexpected packet format.
重新启动应用程序池后,服务可以正常工作大约15分钟,之后又会出现相同的错误。我的应用程序池没有设置内存限制。
app.config配置文件如下所示:
解决这一问题的关键在于确保使用了正确的安全协议。根据帖子“如何仅使用TLS进行出站连接而不回退到SSL(针对POODLE漏洞的缓解措施)”,我发现之前的服务调用中设置了以下代码,导致了SSL3的使用:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
为了防止此类问题的发生,需要将安全协议类型设置为TLS,正如上述帖子中的建议所言。