Can any one have worked and send the push notification the the apple device from the wcf project. I am trying to do it, but getting the certificate error. if any one have imlement this please help me out..
Thanks..
Code wich i am using ..
tiwari-mike
string str = string.Empty;
int port = 1234;
String deviceID = objInput.deviceId; // "4564c705 63b371aa 3811699e 1e4ac3d2 ba592b27 f2a5a613 d25cd035 xx213e54";
// String hostname = "gateway.sandbox.push.apple.com"; // TEST
String hostname = "gateway.push.apple.com"; // REAL
String certificatePath = HttpContext.Current.Server.MapPath("PushChatKey.p12");
X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
try
{
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Default, false);
}
catch (Exception e)
{
throw (e);
client.Close();
return;
}
if (type == "1")
{
str = "{\"Title\":\"" + objInput.title + "\",\"SubTitle\":\"" + objInput.subTitle + " Points. \",\"Point\":\"" + objInput.objCustPoint.point + "\"," + "\"Type\":\"" + objInput.type + "\"}";
// str = "{\"Title\":\"" + objInput.title + "\",\"Point\":\"" + objInput.objCustPoint.point + "\"," + "\"Type\":\"" + objInput.type + "\"}";
}
if (type == "2")
{
str = "{\"Title\":\"" + objInput.title + "\",\"SubTitle\":\"" + objInput.subTitle + "\",\"StartDate\":\"" + objInput.objCustPoint.custID + "\"," + "\"EndDate\":\"" + objInput.objCustPoint.POSID + "\"," + "\"Type\":\"" + objInput.type + "\"}";
}
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0); //The command
writer.Write((byte)0); //The first byte of the deviceId length (big-endian first byte)
writer.Write((byte)32); //The deviceId length (big-endian second byte)
writer.Write(HexStringToByteArray(deviceID.ToUpper()));
String payload = str;// "{\"aps\":{\"alert\":\"hello\",\"badge\":0,\"sound\":\"default\"}}";
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();
Pl