Receiving a Raw Notification

,

To receive a raw notification in an app, subscribe to the HttpNotificationChannel.HttpNotificationReceived event, as shown:

channel.HttpNotificationReceived += channel_HttpNotificationReceived;
...
void channel_HttpNotificationReceived(object sender,
                                             HttpNotificationEventArgs e)
{
...
}

When the HttpNotificationReceived event is raised, the handler receives an HttpNotificationEventArgs object that contains a Notification property of type HttpNotification. HttpNotification contains the following properties:

Image Body—The payload for the notification. This is the main property of interest. It is a Stream containing the raw notification data.

Image Channel—The channel to which the notification arrived.

Image Headers—The request headers that were supplied during the creation of the notification.

The following excerpt from the PushNotificationViewModel class in the downloadable sample code demonstrates how raw notification is handled on the phone, and in particular how the content object (in this case, a StockQuote) is rehydrated:

void subscriber_HttpNotificationReceived(
    object sender, HttpNotificationEventArgs e)
{
    Message = "Raw notification received.";
    Stream bodyStream = e.Notification.Body;

    if (bodyStream != null)
    {
        DataContractJsonSerializer serializer
                = new DataContractJsonSerializer(typeof(StockQuote));

        StockQuote = (StockQuote)serializer.ReadObject(bodyStream);
    }
}

A DataContractJsonSerializer reverses the serialization process by transforming the stream data back to a StockQuote object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.115.131