I'm getting the following error message trying to send a push notification to my iPhone:
Apple Notification Failed: ID={12}, Code= {PushSharp.Apple.ApnsConnectionException: SSL Stream Failed to Authenticate as Client---> System.Security.Authentication.AuthenticationException: Could not make a call to SSPI; see the internal exception. ---> System.ComponentModel.Win32Exception: Message received unexpectedly, or its format is incorrect}
I'm using PushSharp library and the following code:
- using PushSharp.Apple;
- using PushSharp.Core;
- using Newtonsoft.Json.Linq;
- string p12fileName = "C:\\webroot\\PKI\\myCertificate.p12";
- string p12password = "myPassword";
- string deviceToken = "myiPhoneToken";
- var appleCert = System.IO.File.ReadAllBytes(p12fileName);
- var config = new PushSharp.Apple.ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, p12password);
- config.ValidateServerCertificate = false;
- var apnsBroker = new ApnsServiceBroker(config);
- apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
- aggregateEx.Handle(ex => {
-
- if (ex is ApnsNotificationException)
- {
- var notificationException = (ApnsNotificationException)ex;
-
- var apnsNotification = notificationException.Notification;
- var statusCode = notificationException.ErrorStatusCode;
- Response.Write("Apple Notification Failed: ID={" + apnsNotification.Identifier + "}, Code={" + statusCode + "}");
- }
- else
- {
-
- Response.Write("Notification Failed for some unknown reason : {" + ex.InnerException + "}");
- }
-
- return true;
- });
- };
- apnsBroker.OnNotificationSucceeded += (notification) => {
- Response.Write("Apple Notification Sent!");
- };
- apnsBroker.Start();
- apnsBroker.QueueNotification(new ApnsNotification
- {
- DeviceToken = deviceToken,
- Payload = JObject.Parse("{\"aps\":{\"alert\":\"" + "Hi,, This Is a Sample Push Notification For IPhone.." + "\",\"badge\":1,\"sound\":\"default\"}}")
- });
- apnsBroker.Stop();
But if I try the same data at website http://pushtry.com/ I can get the push notification.
I created the certificate more than once trying to avoid any error at create certificate moment.
What I'm doing wrong? What is missing in my code?
Can anyone help me?
Kind regards in advance.