I want to send the Push notification to send ios device using WCF service.
When i run the service from Local Machine the push notification is send to the server
but when it is hosted on iis notification is not send.
i am receiving following error:
error:-
A call to SSPI failed, see inner exception
inner exception:
System.ComponentModel.Win32Exception " +
"(0x80004005): The message received was unexpected or badly formatted
What I have tried:
public string PushNotificationIOS(string deviceID)
{
string devicetocken=string.Empty;
try
{
devicetocken = deviceID;
int port = 2195;
String hostname = "gateway.sandbox.push.apple.com";
string certificatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Certificate/Certificates.pem");
string certificatePassword = "Sudesi@123";
X509Certificate2 clientCertificate = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null
);
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, false);
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0);
writer.Write((byte)0);
writer.Write((byte)32);
byte[] b0 = HexString2Bytes(devicetocken);
writer.Write(b0);
String payload;
string strmsgbody = "";
int totunreadmsg = 20;
strmsgbody = "Your call for complaint no. M00011 has been registered in our system. - Your ticket no for your communication is 100000000065";
payload = "{\"aps\":{\"alert\":\"" + strmsgbody + "\",\"badge\":" + totunreadmsg.ToString() + ",\"sound\":\"mailsent.wav\"},\"acme1\":\"bar\",\"acme2\":42}";
writer.Write((byte)0);
writer.Write((byte)payload.Length);
byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
writer.Write(b1);
writer.Flush();
byte[] array = memoryStream.ToArray();
sslStream.Write(array);
sslStream.Flush();
client.Close();
return "True";
}
catch (AuthenticationException ex)
{
return ex.Message;
}
catch (Exception ex)
{
return ex.Message;
}
}