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:
Body—The payload for the notification. This is the main property of interest. It is a Stream
containing the raw notification data.
Channel—The channel to which the notification arrived.
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.
3.141.47.25