C#发布请求Windows 10无法创建SSL / TLS安全通道

时间:2018-09-19 14:13:12

标签: c# windows-services

我有一个在Windows Service Timer Tick中运行的方法。 基本上,我每分钟都会发送存储在队列中的短信。

假设我要发送4条消息。

假设在每个计时器刻度上我们有4条消息要发送。

Sms GateWay提供程序正在使用tls1.2-如果我使用ServicePointManager设置协议类型-则具有相同的行为。

假设我使用4.6.1 Net Framework和Win 10 Pro

在第一次计时时,将发送每条消息。 在第2、3,...,n个计时器滴答消息3、4、5发送,但不是第1个。总是。 我正在从主题获得异常请求被中止:无法创建SSL / TLS安全通道

HttpClient.PostAsync returned   Id = 19, Status = Faulted, Method = "{null}", Result = "{not yet computed}"  System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>

以下方法的工作原理很吸引人,例如win 7 pro,但在Win 10 Pro上

public async Task SendAsync(IEnumerable<Message> messages)
    {
        using (var client = new HttpClient())
        {
            foreach (Message m in messages)
            {
                _content = Extensions.SmsApiConfiguration.GetConfig();

                //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
                //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                var httpContent = new FormUrlEncodedContent(_content);

                try
                {
                    var response = await client.PostAsync(API_URL, httpContent);

                    if (response.IsSuccessStatusCode)
                    {
                        var responseContent = await response.Content.ReadAsStringAsync();
                        File.AppendAllText(@"D:\log_service.txt", Environment.NewLine + " " + responseContent);

                    }
                }
                catch (Exception ex)
                {
                    File.AppendAllText(_logFilePath, Environment.NewLine + " " + ex);
                }
            }
        }
    }

并在onStart()方法中使用它

    private void timer_Elapsed(object sender, ElapsedEventArgs e)
    {
        // messageRepository - get messages to be send
        // SerwerSMSService - use of api external gate
        MessageService message = new MessageService(new MessageRepository(), new SerwerSMSService());

        message.SendSms();

    }

例如,我尝试了所有设法找到的东西

0 个答案:

没有答案