locked
[WPSL] Push notification not received RRS feed

  • Question

  • Hi all ,

    I Have implement a push notification service.We create successfully a channel uri.Ten call with the channel uri from server site it's return "OK" but we not received any push notification.We upload the app in dev store also upload the go daddy SSL cirtificate for push.

    Here is my code from client end:

    using Microsoft.Phone.Notification;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Threading;
    
    namespace OTT.Common
    {
        public class clsPushNotification
        {
            /// Holds the push channel that is created or found.
            HttpNotificationChannel pushChannel;
            // The name of our push channel.
            string channelName = "ToastSampleChannel";//"CAlertPushChannel";
            string serviceName = "www.abc.com"; //"www.calert.com";
            string channelURI = "";
    
            public void CallPushNotification()
            {  
    
                // Try to find the push channel.
                pushChannel = HttpNotificationChannel.Find(channelName);
    
                // If the channel was not found, then create a new connection to the push service.
                if (pushChannel == null)
                {
                    //pushChannel = new HttpNotificationChannel(channelName);
                    pushChannel = new HttpNotificationChannel(channelName, serviceName);
                    //pushChannel = new HttpNotificationChannel(channelName);
    
                    // Register for all the events before attempting to open the channel.
                    pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                    pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
    
                    // Register for this notification only if you need to receive the notifications while your application is running.
                    pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
    
    
                    pushChannel.Open();
    
                    // Bind this new channel for toast events.
                    pushChannel.BindToShellToast();              
                    pushChannel.BindToShellTile();
                }
                else
                {
                    try
                    {
                        // The channel was already open, so just register for all the events.
                        pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                        pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
    
                        // Register for this notification only if you need to receive the notifications while your application is running.
                        pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                        pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
                        channelURI = pushChannel.ChannelUri.ToString();
                    }
                    catch { }
                    
                }
            }
    
            void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    channelURI = pushChannel.ChannelUri.ToString();
                    
                });
            }
    
            void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
            {
                // Error handling logic for your particular application would be here.
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}",
                      e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
                      );
            }
    
            void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {                        
                    string Param = e.Collection["wp:Param"];
                    Param = Param.Split('=')[1];
                    //clsGetcAlertDetails objclsGetcAlertDetails = new clsGetcAlertDetails();
                    //objclsGetcAlertDetails.GetcAlertDetails(Param);
                    //objclsGetcAlertDetails = null;
                    
                    //MessageBox.Show(PushText);
                    //Toast.Toast_Prompt Toast = new Toast.Toast_Prompt();
                    //Toast.ToastMessage = e.Collection["wp:Text2"];
                    //Toast.ToastTitle = e.Collection["wp:Text1"];
                    //String ph_number = e.Collection["wp:Param"].Remove(0, e.Collection["wp:Param"].IndexOf('+') + 1);
                    //ph_number = ph_number.Remove(ph_number.IndexOf('\''), ph_number.Length - ph_number.IndexOf('\''));
                    //Toast.Tag = ph_number;
                    //Toast.ToastBackground = Application.Current.Resources["PhoneAccentBrush"] as SolidColorBrush;
                    //Toast.Show();
                    //Toast.ClickToast += new Toast.Toast_Prompt.OnClicKToast(Toast_ClickToast);
                });
    
                ////StringBuilder message = new StringBuilder();
                ////string relativeUri = string.Empty;
    
                ////message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());
    
                ////// Parse out the information that was part of the message.
                ////foreach (string key in e.Collection.Keys)
                ////{
                ////    message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);
    
                ////    if (string.Compare(
                ////    key,
                ////    "wp:Param",
                ////    System.Globalization.CultureInfo.InvariantCulture,
                ////    System.Globalization.CompareOptions.IgnoreCase) == 0)
                ////    {
                ////        relativeUri = e.Collection[key];
                ////    }
                ////}
    
            }
            private void Toast_ClickToast(object sender, EventArgs e)
            {
                //Toast.Toast_Prompt Toast = sender as Toast.Toast_Prompt;
                //(Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Navigate(new Uri("/Pages/frmDetailMessage.xaml?ph_num=" + Toast.Tag.ToString() + "&Contact_Header=" + Toast.Tag.ToString(), UriKind.Relative));
                //Toast = null;
            }
    
            void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
            {
                using (StreamReader reader = new StreamReader(e.Notification.Body))
                {
                    string message = reader.ReadToEnd();
                    //Dispatcher.BeginInvoke(() => MessageBox.Show(message));
                }
            }
        }
    }
    

    Here is the code from serverside:

    try
            {
                // Get the URI that the Microsoft Push Notification Service returns to the push client when creating a notification channel.
                // Normally, a web service would listen for URIs coming from the web client and maintain a list of URIs to send
                // notifications out to.
                string subscriptionUri = TextBoxUri.Text.ToString();
    
    
                HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);
    
                // Create an HTTPWebRequest that posts the raw notification to the Microsoft Push Notification Service.
                // HTTP POST is the only method allowed to send the notification.
                sendNotificationRequest.Method = "POST";
    
                // Create the raw message.
                string rawMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<root>" +
                    "<Value1>" + TextBoxValue1.Text.ToString() + "<Value1>" +
                    "<Value2>" + TextBoxValue2.Text.ToString() + "<Value2>" +
                "</root>";
    
                // Set the notification payload to send.
                byte[] notificationMessage = Encoding.Default.GetBytes(rawMessage);
    
                // Set the web request content length.
                sendNotificationRequest.ContentLength = notificationMessage.Length;
                sendNotificationRequest.ContentType = "text/xml";
                sendNotificationRequest.Headers.Add("X-NotificationClass", "3");
    
    
                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"];
    
                // Display the response from the Microsoft Push Notification Service.  
                // Normally, error handling code would be here. In the real world, because data connections are not always available,
                // notifications may need to be throttled back if the device cannot be reached.
                string dfdfd = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
            }
            catch (Exception ex)
            {
                //TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
            }
    Here is my channe URI

    http://s.notify.live.net/u/1/db3/H2QAAABX0Irm-O_0ONKyo1E6hrRnek5Y2g_jCETO3SzvXNfvBxz9c7ScAn-VQffq_JAaXrjGWOHyBY-AgYapGNwuo4yTRC26KtGIlYU4FmivWDnVKv3KXKKB5JCRr1ahM7x77Hs/d3d3LmFwcHMuc2JjLnNh/PmwHr_FiOEq5sDjKDFjK9A/Snj6NmKBFZOZDAa3LHASEiPtLuU

    Please suggest how to receive my notification:

    Tuesday, October 6, 2015 1:01 PM

Answers

  • Hello sudip_int,

    I recommend you could check the official notification sample Toast Notification Sample, it demonstrates how to send a toast notification to a Windows Phone using the Microsoft Push Notification Service. You could just follow it to get your goal.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Proposed as answer by Fred Bao Monday, October 19, 2015 11:40 AM
    • Edited by Fred Bao Thursday, October 22, 2015 4:44 AM
    • Marked as answer by Fred Bao Thursday, October 22, 2015 4:44 AM
    Wednesday, October 7, 2015 9:30 AM