Question

I am using PushSharp to send Apple Push Notification in C# , i have my production .pem file and its password. Below is my code snippet.Am always getting this error ..

"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."

I tried almost all codes available in net.Even tried MoonAPNS but same error, For custom script also am getting this SSPI failure error. I use the same .pem file and run a php script to send push notification to APN from same server,it works.

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();

Please help Thanks in advance

Was it helpful?

Solution

I think your c# may be incorrect, To verify, rather than with a .pem, can you try with your p12 cert using the below code as a test...

    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);`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top