Hi All,
I am new to push notification for Windows Phone 7.
Can anyone instruct and tell me code for Windows Phone 7 server side push notification in Java.
I have tried the following code but it is not working and showing errors.
String subscriptionUri="";
HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);
sendNotificationRequest.Method = "POST";
//Indicate that you'll send toast notifications!
sendNotificationRequest.ContentType = "text/xml";
sendNotificationRequest.Headers = new WebHeaderCollection();
sendNotificationRequest.Headers.Add("X-NotificationClass", "2");
//if (String.IsNullOrEmpty(txtMessage.Text)) return;
//Create xml envelope
String data = "X-WindowsPhone-Target: toast\r\n\r\n" +
"='1.0'='utf-8'" +
"<wp:Notification xmlns:wp='WPNotification'>" +
"<wp:Toast>" +
"<wp:Text1>{0}</wp:Text1>" +
"</wp:Toast>" +
"</wp:Notification>";
//Wrap custom data into envelope
//String message = String.Format(data, txtMessage.Text);
byte[] notificationMessage = Encoding.Default.GetBytes(data);
// Set Content Length
sendNotificationRequest.ContentLength = notificationMessage.length;
//Push data to stream
using (Stream requestStream = sendNotificationRequest.GetRequestStream())
{
requestStream.Write(notificationMessage, 0, notificationMessage.Length);
}
try
{
//Get reponse for message sending
HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
String notificationStatus = response.Headers["X-NotificationStatus"];
String notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
String deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
return (int) response.StatusCode;
}
catch (WebException ex)
{
return (int) ((HttpWebResponse) ex.Response).StatusCode;
}
1)It is showing error on the line-
HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);
2)I have import following class-
import org.omg.IOP.Encoding;
import java.net.*;
import java.io.*;
import javapns.back.PushNotificationManager;
import javapns.back.SSLConnectionHelper;
import javapns.data.Device;
import javapns.data.PayLoad;
Can anyone help me in removing error or tell some other code for the same.
Thanks ane Regards.