【问题标题】:Secure connection errors from a Windows Service来自 Windows 服务的安全连接错误
【发布时间】:2015-11-05 09:20:19
【问题描述】:

我有一个正在向安全网页发送数据的 Windows 服务。这目前在通过 Visual Studio 2010 运行的控制台应用程序中运行良好。我已经能够使用这种方法连接和发送数据。

当我部署和运行 Windows 服务时出现问题,我现在收到以下错误“请求已中止:无法创建 SSL/TLS 安全通道。”

这是我用来在网页上发布 http 的代码

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback +=
            (sender, cert, chain, sslPolicyErrors) => true;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.ContentType = "text/xml; encoding='utf-8'";
        request.Method = "POST";
        doc.Save(request.GetRequestStream());

        X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);

        var certif = store.Certificates.Find(X509FindType.FindByThumbprint, "‎539B640BD981BFC48A366B8981B66F301C8A3959", false);
        request.ClientCertificates.Add(certif);
        try
        {
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {

            if (response.StatusCode == HttpStatusCode.OK)
            {
                success = true;
            }
        }

        }
        catch (Exception ex)
        {
            error = ex.Message + " " + ex.InnerException;
        }

我检查了证书存储,正确的证书位于 Windows 服务的受信任根目录中。 TLS/SSL 连接的另一个方面是否与窗口服务不同?任何人的想法将不胜感激。

【问题讨论】:

    标签: c# ssl service client-certificates


    【解决方案1】:

    如果有人遇到类似的行为,问题就出现了,因为 Windows 服务没有足够的权限。如果服务以我自己的身份登录,它只能在我的本地机器上工作。当 Windows 服务以管理员身份登录时,它仅在单独的服务器上工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      相关资源
      最近更新 更多