locked
Push Notification Issue

    Question

  • Hello,

     I am developing an application for a newspaper in Arabic and I have implemented push notifications for breaking news, the push works great but i have a problem with the Arabic text being sent with the push... when the client receives the message the Arabic letters are replaced with question marks ( ???? ) .
    any ideas about what encoding i should use ? 

    Thanks In advance!

    Here is my "onsend" btn click C# code:

            protected void ButtononSend_Click(object sender, EventArgs e)
            {
                try
                {             
                    string subscriptionUri = TextBoxUri.Text.ToString();
                    HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);               
                    sendNotificationRequest.Method = "POST";
                   
                    // sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>");

                    // Create the toast message.
                    string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                    "<wp:Notification xmlns:wp=\"WPNotification\">" +
                       "<wp:Toast>" +
                            "<wp:Text1>" +  TextBoxTitle.Text.ToString() + "</wp:Text1>" +
                            "<wp:Text2>" + TextBoxSubTitle.Text.ToString() + "</wp:Text2>" +
                            "<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>" +
                       "</wp:Toast> " +
                    "</wp:Notification>";

                    // Sets the notification payload to send.
                    //byte[] notificationMessage = Encoding.Default.GetBytes(toastMessage);
                    byte[] notificationMessage = Encoding.GetEncoding("ISO-8859-1").GetBytes(toastMessage);

                    // Sets the web request content length.
                    sendNotificationRequest.ContentLength = notificationMessage.Length; 
                    sendNotificationRequest.ContentType = "text/xml";
                    sendNotificationRequest.ContentType = "charset=ISO-8859-1";
                    sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
                    sendNotificationRequest.Headers.Add("X-NotificationClass", "2");


                    using (Stream requestStream = sendNotificationRequest.GetRequestStream())
                    {
                        requestStream.Write(notificationMessage, 0, notificationMessage.Length);
                    }

                    // Send the notification and get the response.
                    HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
                    string notificationStatus = response.Headers["X-NotificationStatus"];
                    string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
                    string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
                  
                    // notifications may need to be throttled back if the device cannot be reached.
                    TextBoxResponse.Text = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
                }
                catch (Exception ex)
                {
                    TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
                }

    Tuesday, September 16, 2014 12:50 PM

Answers

  • This is probably because your toastMessage says that its text is in UTF-8 but you're encoding it in ISO-8859-1. I suspect this confuses the client into interpreting the characters incorrectly.

    I'd use UTF-8 for the entire path.

    --Rob

    • Marked as answer by Subiya Wednesday, September 17, 2014 6:04 AM
    Tuesday, September 16, 2014 7:16 PM
    Owner

All replies

  • This is probably because your toastMessage says that its text is in UTF-8 but you're encoding it in ISO-8859-1. I suspect this confuses the client into interpreting the characters incorrectly.

    I'd use UTF-8 for the entire path.

    --Rob

    • Marked as answer by Subiya Wednesday, September 17, 2014 6:04 AM
    Tuesday, September 16, 2014 7:16 PM
    Owner
  • Hello Rob,

    Thanks a ton!! Its working perfectly..:)

    Regards,

    Subiya.

    Wednesday, September 17, 2014 6:04 AM