2017-09-25 21 views
0
내가 뭔가 잘 작동하고

System.Net.WebException : 요청이 중단되었습니다 : SSL/TLS 보안 채널을

using (var wc = new WebClient()) 
{ 
    wc.Headers.Add("Authorization", "Key=" + ConfigurationSettings.AppSettings["apiKey"]); 
    var nameValues = new NameValueCollection 
    { 
     {"registration_id", objSendNotificationBE.RegistrationID}, 
     {"collapse_key", Guid.NewGuid().ToString()}, 
     {"data.payload", objSendNotificationBE.Message} 
    }; 
    var resp = wc.UploadValues("https://android.googleapis.com/gcm/send", nameValues); 
    respMessage = Encoding.Default.GetString(resp); 
    if (respMessage == "Error=InvalidRegistration") 
    { 
     string respMessage = ""; 
    } 
} 

내 WCF 웹 서비스에서 푸시 알림을 보낼 수 아래의 코드를 사용하고

하지만 가끔은를 만들 수 없습니다 예외가 발생했습니다

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. 
    at System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data) 
    at System.Net.WebClient.UploadValues(String address, NameValueCollection data) 

하늘빛 서버에 웹 서비스를 배포했습니다.

+0

에 대답 볼 수 있습니까? 지금은 읽기가 어렵습니다 – dat3450

+0

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12를 추가하려고합니다. (var wc = new WebClient())를 사용하기 전에 – jitender

+0

친애하는 Jitender 고맙습니다.하지만이 문제는 정기적으로 발생하지는 않겠다는 언급을 들었습니다. – Siddhartha

답변

0

SSL/TLS를 사용하는 사이트 (https로 시작)로 요청을 보내고 있습니다. 의견에서 언급 한 것처럼 SSL/TLS를 사용하도록 웹 클라이언트를 구성해야합니다. 도달하려는 원격 서버가 SSL 또는 TLS를 사용하는지 확인한 다음 올바른 보안 모드를 사용해야합니다.

이가 제대로 코드를 포맷 할 수 있습니다 this question.

using System.Net; 
using System.Net.Security; 
using System.Security.Cryptography.X509Certificates; 

class Program 
{ 
    static void Main(string[] args) 
    { 
     Uri address = new Uri("https://archive.org/details/OTRR_In_The_Name_Of_The_Law_Singles"); 

     ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; 
     ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 ; 

     using (WebClient webClient = new WebClient()) 
     { 
      var stream = webClient.OpenRead(address); 
      using (StreamReader sr =new StreamReader(stream)) 
      { 
       var page = sr.ReadToEnd(); 
      } 
     } 
    } 

    /// <summary> 
    /// Certificate validation callback. 
    /// </summary> 
    private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) 
    { 
     // If the certificate is a valid, signed certificate, return true. 
     if (error == System.Net.Security.SslPolicyErrors.None) 
     { 
      return true; 
     } 

     Console.WriteLine("X509Certificate [{0}] Policy Error: '{1}'", 
      cert.Subject, 
      error.ToString()); 

     return false; 
    } 
} 
+0

이 두 줄을 추가하여이 문제점을 해결합니다. ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls; 그러나 나는 왜 우리가 웹 서비스를 호출 할 때마다 이런 오류가 오지 않는지 알 수 없다. – Siddhartha

관련 문제