2013-09-01 114 views
3

我使用PushSharp在C#中發送Apple推送通知,我有我的生產.pem文件及其密碼。下面是我的代碼snippet.Am總是收到此錯誤..Pushsharp蘋果通知調用SSPI失敗錯誤

"A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted-" 

OR

"System.IO.IOException: Authentication failed because the remote party has closed the transport stream." 

我幾乎嘗試了所有可用的net.Even代碼試圖MoonAPNS但同樣的錯誤,對於自定義腳本也正在逐漸此SSPI失敗錯誤。我使用相同的.pem文件,並運行一個php腳本從同一臺服務器向APN發送推送通知,它的工作原理。

var push = new PushBroker(); 
var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ck.pem")); 
push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "pwd")); 
push.QueueNotification(new AppleNotification() 
              .ForDeviceToken("XXXXXXXXXXXXXXX") 
              .WithAlert("Hello World!") 
              .WithBadge(7) 
              .WithSound("sound.caf")); 


       LogManager.Info("Waiting for Queue to Finish.."); 
       push.StopAllServices(); 

請幫忙提前

回答

1

謝謝,我覺得你的C#可能是不正確的,要進行驗證,而不是爲.pem,你可以嘗試用你的P12證書使用下面的代碼進行測試。 ..

Boolean bsandbox = true; 
    string p12fileName =AppDomain.CurrentDomain.BaseDirectory + "yourCert.p12"; 
    string p12password = "1234"; 

    string deviceID1 = "2909b25e0c699b2dc4864b4b9f719e67aac7e0fab791a72a086ffb788ba28f6a"; // 
    string msg = "This is the message sent at : "; 
    string alert = "Hello world at " + DateTime.Now.ToLongTimeString(); 
    int badge = 1; 
    string soundstring = "default"; 
    var payload1 = new NotificationPayload(deviceID1, alert, badge, soundstring); 
    payload1.AddCustom("custom1", msg); 

    var notificationList = new List<NotificationPayload> { payload1 }; 



    var push = new PushNotification(bsandbox, p12fileName, p12password); 

    var rejected = push.SendToApple(notificationList);` 
+0

是啊約翰......你是對的。其p12文件用於推動銳利。我正在使用pem文件。問題解決與p12文件。謝謝 – ramesh

+0

樂意幫忙! – Woodstock

+0

我正在使用相同的代碼來推送,但是卻得到一個異常:您選擇了開發/沙箱(非生產)服務器,但您的證書似乎並不是開發/沙盒證書!請檢查以確保您擁有正確的證書! – Legnus