[英]Secure connection errors from a Windows Service
我有一個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連接的另一方面是否與Window Service不同? 人們的任何想法將不勝感激。
如果有人遇到類似的行為,則會出現問題,因為Windows服務沒有足夠的權限。 如果服務以我自己的身份登錄,則只能在本地計算機上使用。 僅當Windows服務以管理員身份登錄時,它才能在單獨的服務器上工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.