我使用下面的代碼從我的WCF Web服務發送推送通知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 = "";
}
}
它的工作很好,但有時我我得到了例外
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)
我已經在azure服務器上部署了我的web服務。
你能正確地格式化你的代碼?目前很難讀取 – dat3450
嘗試添加ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;在使用之前(var wc = new WebClient()) – jitender
親愛的Jitender thanx的回覆,但正如我所提到的,這個問題有時候會不經常發生,我該如何檢查它爲什麼只發生一段時間而不是所有的請求。 – Siddhartha