I.Introduction
Push notificationYesWindows Phone 7One of the special features in, this feature allows common developers to achieve multi-tasking in disguise (although not really multi-tasking ). It is a mobile app andWebServiceA dedicated, persistent, and stable channel is established between them to push notifications. After the channel is established, the mobile app can receiveWebService.
II.Category
ForPush notificationThere are three main types:
1.Tile notification:
Yes, it can be changed.Quick lanuch AreaIcon content (image, text, etc.) in. HoweverProgramPIN to start,.
2.Toast notification:
Display a prompt bar on the screen. Click the prompt bar to open the application.
3.Raw notification:
Is used directlyHTTPMethod to receive (HTTP polling) Notification method. And is invisible. notifications will be sent in the future.
For the above notifications, a server mustPush notificationTo send notifications, That is to say to usePush notificationAll require a server.
III.Create a server
For the server, sending different notifications is based onHTTPMethod, but when sending, You need to configure the corresponding parameters to tellPush Notification ServiceWhat is the sending type.
HttpwebrequestRequest = (Httpwebrequest)Webrequest. Create (channeluri );
Request. method =Webrequestmethods.HTTP. Post;
Request. contenttype ="Text/XML; charset = UTF-8";
Request. contentlength = icationicationmessage. length;
Request. headers ["X-messageid"] =Guid. Newguid (). tostring ();
1. Toast notification:
Request. headers ["X-windowsphone-target"] ="Toast";
Request. headers [X-icationicationclass]
Message:
"Content-Type: text/XML \ r \ NX-windowsphone-target: token \ r \ n"
<? XML version = "1.0" encoding = "UTF-8"?>
<WP: Notification xmlns: Wp = "wpnotification">
<WP: Tile>
<WP: backgroundimage>
<Background image path>
</WP: backgroundimage>
<WP: Count>
<Count>
</WP: Count>
<WP: title>
<Title>
</WP: title>
</WP: Tile>
</WP: Notification>
2. Token notification:
Request. headers ["X-windowsphone-target"] ="Token";
Request. headers [X-icationicationclass]
Message:
"Content-Type: text/XML \ r \ NX-windowsphone-target: Toast \ r \ n"
<? XML version = "1.0" encoding = "UTF-8"?>
<WP: Notification xmlns: Wp = "wpnotification">
<WP: Toast>
<WP: text1>
<String>
</WP: text1>
<WP: text2>
<String>
</WP: text2>
</WP: Toast>
</WP: Notification>
3. Raw notification
Request. headers [X-icationicationclass]
Request. begingetrequeststream ();
StreamRequeststream = request. endgetrequeststream ();
Requeststream. beginwrite (Message );
ResponseData
Response. statuscode// OKOtherwise, you can check the corresponding error code table and check the table to get the current status.
Response. headers [X-messageid]
Response. headers [X-deviceconnectionstatus]
Response. headers [X-subscriptionstatus]
Response. headers [X-icationicationstatus]
4.Create a client
HttpicationicationchannelHttpchannel =Httpicationicationchannel. Find (channelname );
Httpchannel. open ();
//BindNotification
Httpchannel. bindtoshelltoast ();
Httpchannel. bindtoshelltile (URIs );
//ObtainNotification channel URI
Httpchannel. channeluriupdated + =New Eventhandler<Icationicationchannelurieventargs> (Httpchannel_channeluriupdated );
//ObtainRaw notification
Httpchannel. httpicationicationreceived + =New Eventhandler<Httpicationeventargs> (Httpchannel_httpicationicationreceived );
//ObtainToast notification
Httpchannel. shelltoastnotificationreceived + =New Eventhandler<Icationicationeventargs> (Httpchannel_shelltoastnotificationreceived );
//ObtainPush notification error message
Httpchannel. erroccurred + =New Eventhandler<Icationicationchannelerroreventargs> (Httpchannel_exceptionoccurred );
ForTile notificationIs received by the system, so there is no correspondingEvent.
The above isPush notificationSome basic steps, the specific instance inWp7trainningkit.