<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Windows 8 app developer blog</title><link>http://blogs.msdn.com/b/windowsappdev/</link><description>Insights on building Windows Store apps by the Windows 8 engineering team</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Create location aware apps using geolocation and Bing Maps</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/05/22/create-location-aware-apps-using-geolocation-and-bing-maps.aspx</link><pubDate>Wed, 22 May 2013 15:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420162</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10420162</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/05/22/create-location-aware-apps-using-geolocation-and-bing-maps.aspx#comments</comments><description>&lt;p&gt;By tying together a user’s location to the business logic of your app, you can easily provide app users with weather, coupons, sporting events, or concert listings for their current location. You can use the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br229921.aspx" target="_blank"&gt;geolocation&lt;/a&gt; capabilities of Windows 8, along with the Bing Maps SDK, to create great &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465148.aspx" target="_blank"&gt;location aware Windows Store apps&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Let’s take a look at how your app can use the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br225603.aspx" target="_blank"&gt;location service&lt;/a&gt; to provide users location-specific info with either an IP address, WiFi network, or GPS data. Once you have the location, you can use the Bing Maps SDK to show the user where they are. &lt;/p&gt;  &lt;h2&gt;Retrieving Location&lt;/h2&gt;  &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.aspx"&gt;Windows.Devices.Geolocation&lt;/a&gt; namespace is used for retrieving your location. Whether you use GPS, a WiFi network, or an IP address to retrieve a user’s location depends on two primary factors:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The accuracy level requested. This is the ideal level of accuracy to meet your app’s needs. &lt;/li&gt;    &lt;li&gt;The availability of location data.&amp;#160; Meaning, not all devices have GPS built in.&amp;#160;&amp;#160; Or a network or Wi-Fi connection may not be available when the location is requested.&lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;&lt;a&gt;Desired accuracy&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;When requesting a location, your app should specify your &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.desiredaccuracy.aspx" target="_blank"&gt;desired accuracy&lt;/a&gt; so the location data can be returned as quickly as possible within the given range.&amp;#160; Each of the location types have degrees of accuracy:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Gps" target="_blank"&gt;GPS&lt;/a&gt; – GPS provides the most accuracy, down to approximately 10 meters.&amp;#160; However, if the GPS sensor needs to ‘wake up’ and acquire satellite data and then triangulate the data, it can take a minute or two to return the location details. But, once the GPS has acquired satellite connections, it can then acquire the next location point more quickly.&amp;#160; Of course, the more the GPS is used, the more power it consumes. The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.desiredaccuracy.aspx" target="_blank"&gt;Geolocator.DesiredAccuracy&lt;/a&gt; property must be set to High to enable to GPS to acquire data.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Wi-Fi" target="_blank"&gt;Wi-Fi&lt;/a&gt; – A Wi-Fi connection can provide accuracy between 300-500 meters.&amp;#160; If the connection exists, the location data can be returned faster than a GPS can acquire satellite connections. Set the DesiredAccuracy property to Default in order to acquire the location with Wi-Fi.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/IP_address" target="_blank"&gt;IP&lt;/a&gt; – IP level resolution can bring accuracy down to about the 1 kilometer level.&amp;#160; If the network connection exists, the location data can be returned faster than a GPS can acquire a satellite connection. You also set the DesiredAccuracy property to Default to acquire the location with IP. The location service returns the highest accuracy it can and lets you know how accurate it is in the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geocoordinate.accuracy.aspx" target="_blank"&gt;Geocoordinate.Accuracy&lt;/a&gt; property.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Consider your desired accuracy value carefully. It can affect your app’s performance and power consumption.&amp;#160; For example, if your app is providing a weather forecast, you rarely need the high accuracy of GPS.&amp;#160; Also be sure to indicate the accuracy of your data by displaying an error radius based on the accuracy of the data returned. Here is the C# code to set your desired accuracy:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;div id="codeSnippetWrapper"&gt;     &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;Geolocator geolocator = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Geolocator();&lt;br /&gt;geolocator.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;br /&gt;No matter what accuracy you want, the call to get your location is: 

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;Geoposition pos = await geolocator.GetGeopositionAsync().AsTask(token);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here’s the JavaScript code that creates an instance of the Geolocator class, sets the desired accuracy, and then gets the current location. Note that the ‘promise’ variable below is a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211867.aspx" target="_blank"&gt;WinJS.Promise&lt;/a&gt; object – you’ll need to use the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh701079.aspx" target="_blank"&gt;done&lt;/a&gt; method to access the data from the call to &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br225537.aspx" target="_blank"&gt;getGeopositionAsync&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; geolocator = Windows.Devices.Geolocation.Geolocator();&lt;br /&gt;geolocator.desiredAccuracy =&lt;br /&gt;Windows.Devices.Geolocation.PositionAccuracy.high;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Get the geoposition, capturing the request in a 'promise' object.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; promise = geolocator.getGeopositionAsync();&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;br /&gt;Remember that if you set your desired accuracy to High, you can’t be assured that the user’s device will be able to return high accuracy. Their PC may not have a GPS or it may be turned off or they may not be connected to Wi-Fi, etc. Always be prepared to gracefully handle these instances of lower accuracy data. How you do this depends on the functionality of your app. Can you continue with lower accuracy? Can you require GPS level accuracy? See the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465148.aspx" target="_blank"&gt;Guidelines for location-aware apps&lt;/a&gt; for more info. 

&lt;h3&gt;Bing Maps&lt;/h3&gt;

&lt;p&gt;The &lt;a href="http://apps.microsoft.com/webpdp/app/97a2179c-38be-45a3-933e-0d2dbf14a142" target="_blank"&gt;Bing Maps app&lt;/a&gt; is a good example of an app that adapts to the accuracy of the location data available to it.&amp;#160; On a desktop PC, which typically doesn’t have GPS or Wi-Fi, it finds the location based on the IP address and &lt;a&gt;zooms in to a region level when mapping &lt;/a&gt;the current location.&amp;#160; On a laptop, which typically has a wireless card, it uses the Wi-Fi to get a more precise location and zoom in further when showing current location.&amp;#160; If the user zooms in even further, the current location icon will show an error radius.&amp;#160; On a device with GPS, Bing Maps gets the high accuracy location data from the GPS and displays a more accurate location.&lt;/p&gt;

&lt;h3&gt;Bing Weather&lt;/h3&gt;

&lt;p&gt;As mentioned above, an app like the &lt;a href="http://apps.microsoft.com/webpdp/app/421ba874-f903-4965-9b82-d60f3ba3cae0" target="_blank"&gt;Bing Weather app&lt;/a&gt; only needs region information.&amp;#160; Because of this, it can specify that it only needs low accuracy allowing it to quickly get a location value back.&amp;#160; This makes the app more responsive to the user.&amp;#160; Other examples of apps that may need only region level information include radio station guides, shopping deals, or local news feeds.&lt;/p&gt;

&lt;h2&gt;Displaying location data with the Bing Maps SDK&lt;/h2&gt;

&lt;p&gt;After you have the location information from your call to &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.getgeopositionasync.aspx" target="_blank"&gt;GetGeopositionAsync&lt;/a&gt;, you’ll want to display it on a map.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;First, convert the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geoposition.aspx" target="_blank"&gt;Geoposition&lt;/a&gt; into a &lt;a href="http://msdn.microsoft.com/en-us/library/hh846500.aspx" target="_blank"&gt;Location&lt;/a&gt; that can be used with Bing Maps, use the following code:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;Location location = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Location(pos.Coordinate.Latitude, pos.Coordinate.Longitude);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;JavaScript:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;promise.done(&lt;br /&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (pos) {&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Get the coordinates of the current location.&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; coord = pos.coordinate,&lt;br /&gt;    location = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Microsoft.Maps.Location(coord.latitude, coord.longitude);&lt;br /&gt; &lt;br /&gt;  },&lt;br /&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (err) {&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Handle the error.&lt;/span&gt;&lt;br /&gt;  });&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Next, display your location using Bing Maps. You can get the Bing Maps SDK &lt;a href="http://visualstudiogallery.msdn.microsoft.com/bb764f67-6b2c-4e14-b2d3-17477ae1eaca"&gt;here&lt;/a&gt;. You’ll also need to get a Bing Maps Key by registering on the Bing Maps Portal and following the instructions for &lt;a href="http://msdn.microsoft.com/en-us/library/ff428642.aspx"&gt;Getting a Bing Maps Key&lt;/a&gt;. When you register make sure you look at the usage restrictions for each type of key and choose one that is appropriate for your app. 

    &lt;br /&gt;Add a Bing Maps control to your designer and insert your key into the credentials.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Page&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:x&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:local&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;using:SimpleMapping&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:d&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://schemas.microsoft.com/expression/blend/2008&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:mc&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://schemas.openxmlformats.org/markup-compatibility/2006&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:Maps&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;using:Bing.Maps&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;x:Class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;SimpleMapping.MainPage&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;mc:Ignorable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;d&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Grid&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Background&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;{StaticResource ApplicationPageBackgroundThemeBrush}&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Maps:Map&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;Map&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Margin&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;0,120,0,0&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Credentials&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;Insert Your Bing Maps Key Here&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Grid&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Page&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Now you can use the following code to the page in your app where the map is displayed. This sets the zoom level of the map and shows the location. Learn more about zoom level in &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj850315.aspx" target="_blank"&gt;How to display your location on a Bing Map&lt;/a&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; zoomLevel = 13.0f;&lt;br /&gt;&lt;br /&gt;Map.SetView(location, zoomLevel);&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;br /&gt;Adding a Bing Maps control to your app in JavaScript and HTML requires a little more work. Add the following &amp;lt;script&amp;gt; tag to the HTML of your app: 

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;script&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;br /&gt;   &lt;span style="color: rgb(255, 0, 0);"&gt;src&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;ms-appx:///Bing.Maps.JavaScript//js/veapicore.js&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;/script&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, you’ll need to create a &amp;lt;div&amp;gt; tag to contain the map, setting the id attribute so that you can access it.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;div&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;=’&lt;span style="color: rgb(255, 0, 0);"&gt;map-div&lt;/span&gt;’&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;div&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Last, you’ll need to initialize the map control in the HTML page. Here’s some JavaScript code that does so:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Load the Microsoft.Maps.Map module and then call getMap when the &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// module has loaded.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; initMap() {&lt;br /&gt;  Microsoft.Maps.loadModule(&lt;span style="color: rgb(0, 96, 128);"&gt;'Microsoft.Maps.Map'&lt;/span&gt;, &lt;br /&gt;    { &lt;br /&gt;      callback: getMap, &lt;br /&gt;      culture: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;en&amp;quot;&lt;/span&gt;, &lt;br /&gt;      homeRegion: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;US&amp;quot;&lt;/span&gt; &lt;br /&gt;  });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Get the div to contain the map from the interface of the app.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; getMap() {&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a new instance of the Map class, passing in the app ID.&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; map = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Microsoft.Maps.Map(&lt;br /&gt;    document.getElementById(mapDivId), &lt;br /&gt;    { credentials: “Insert your credentials here” });&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: rgb(0, 128, 0);"&gt;// Set the initial zoom level and type of map.&lt;/span&gt;&lt;br /&gt;  map.setView({&lt;br /&gt;    mapTypeId: Microsoft.Maps.MapTypeId.road,&lt;br /&gt;    zoom: 3&lt;br /&gt;  });&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Finally, any app that uses location must respect the user’s permissions settings, which can change at any time.&amp;#160; The Weather app uses location to get the weather for the current location.&amp;#160; But at any time, the user may go into the Settings and turn the Locations permissions off.&amp;#160; Your app always has to handle the possibility that the Location permission has been disabled.&amp;#160; In this case, the Weather app displays a “Your location cannot be found. Change your Permissions to allow Weather to user your location.” message. See the User experience guidelines in &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/Hh465148(v=win.10).aspx" target="_blank"&gt;Guidelines for location-aware apps&lt;/a&gt; for examples of handling location permissions. 

    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0882.bing_2D00_weather_5F00_2FEEBCEF.jpg"&gt;&lt;img title="Bing Weather app" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Bing Weather app using location to get weather for the current location" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7356.bing_2D00_weather_5F00_thumb_5F00_084840C5.jpg" width="600" height="450" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;For full details on using geolocation and the Bing Maps SDK, &lt;a&gt;&lt;/a&gt;&lt;a&gt;we have a new &lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj850315.aspx" target="_blank"&gt;video, how-to topic&lt;/a&gt; , and &lt;a href="http://code.msdn.microsoft.com/windowsapps/Simple-geolocation-with-7b385c3c" target="_blank"&gt;code sample&lt;/a&gt; that leads you through the steps of asynchronously acquiring your location and then using the Bing Maps SDK to show where you are in a visual manner. The video, how-to topic, and sample guide you through enabling the location capability, getting the location asynchronously, setting the map to a given location, and setting the location icon based on the accuracy of the location data. You can also find more info in &lt;a href="http://msdn.microsoft.com/en-us/library/hh846481.aspx" target="_blank"&gt;Bing Maps for Windows Store Apps&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Wrapping up&lt;/h2&gt;

&lt;p&gt;Location can be a powerful and time saving feature to add to your app. You can provide the user with more pertinent information based on where they are. Whether it’s a list of local radio stations, shopping deals, traffic information, or weather information, the control to tailor that information based on location can make your app more useful. And the ability to make that happen automatically, without user interaction, saves the user time and makes them more likely to use your app.&lt;/p&gt;

&lt;p&gt;--Ross Heise, Senior Content Developer, Windows Developer Content&lt;/p&gt;

&lt;p&gt;&amp;#160;&amp;#160; Special thanks to Jon Kay and Eric Schmidt for their help and contributions to this post.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420162" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Bing+Maps/">Bing Maps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/geolocation/">geolocation</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows-Devices-Geolocation/">Windows.Devices.Geolocation</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/location+services/">location services</category></item><item><title>Introducing a new Windows Dev Center experience</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/05/15/introducing-a-new-windows-dev-center-experience.aspx</link><pubDate>Wed, 15 May 2013 20:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10418629</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10418629</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/05/15/introducing-a-new-windows-dev-center-experience.aspx#comments</comments><description>&lt;p&gt;Since launching the &lt;a href="http://msdn.microsoft.com/en-us/windows/default.aspx" target="_blank"&gt;Windows Dev Center&lt;/a&gt; in October, 2011, we’ve worked closely with developers and designers around the world to understand how we can provide the best guidance, inspiration, and samples for app builders. With millions of visitors and your feedback, we’ve been evaluating what’s been working well and what experiences can be improved.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0172.windows_5F00_dev_5F00_center_5F00_1EC86298.png"&gt;&lt;img title="Windows Developer Center" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Windows Developer Center" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0184.windows_5F00_dev_5F00_center_5F00_thumb_5F00_1DEFFCAE.png" width="600" height="338" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;What’s new&lt;/h2&gt;  &lt;p&gt;The Windows team is focused on growing a vibrant and thriving app ecosystem. This is manifested in three ways: great apps, great economics, and great reach opportunity. The new Dev Center connects app builders, designers and businesses with the resources they need to succeed in developing great apps and building a business with Windows.&lt;/p&gt;  &lt;p&gt;To support those goals, the Dev Center evolved in these areas:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The navigation model has changed so you can find the content relevant to where you are in the app development lifecycle&lt;/li&gt;    &lt;li&gt;The site design highlights top tasks, scenarios, and new content &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In addition to the content, samples, and downloads that developers want; we’ve made it easier to access resources for designers and businesses. &lt;/p&gt;  &lt;p&gt;Depending on what you’re building, you can navigate to one of four areas: &lt;a href="http://msdn.microsoft.com/en-US/windows/apps/br229512" target="_blank"&gt;Windows Store apps&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-US/ie/" target="_blank"&gt;Internet Explorer&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-US/windows/desktop" target="_blank"&gt;Windows desktop&lt;/a&gt;, and &lt;a href="http://msdn.microsoft.com/en-US/windows/hardware" target="_blank"&gt;Hardware&lt;/a&gt;. Each of these presents a new experience that addresses the points mentioned above. In this post, we’ll take a closer look at the specific changes made for Windows Store apps.&lt;/p&gt;  &lt;h2&gt;The right content for your role&lt;/h2&gt;  &lt;p&gt;The most informative website isn’t useful if you can’t find what you’re looking for. With hundreds of thousands of topics in the Dev Center, organization and discoverability of content is critical. For Windows Store app development, that means a tighter focus based on role and scenario – from putting everything you need to get started in one place, to better support for designers and businesses. Here are some of the highlights.&lt;/p&gt;  &lt;h3&gt;Developers&lt;/h3&gt;  &lt;p&gt;We’ve streamlined the content you need to build great Windows Store apps. When you go to the &lt;a href="http://msdn.microsoft.com/en-US/windows/apps/" target="_blank"&gt;Windows Store apps home page&lt;/a&gt;, you’ll see: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;“Key tasks and content” prominently called out to help you jump into the content you need. Local events in your region are highlighted, as well as new resources just added to the site. &lt;/li&gt;    &lt;li&gt;Downloads to help you dive right into coding, all the resources you need to get started, and our detailed guidance on getting your app into the Windows Store. &lt;/li&gt;    &lt;li&gt;Important code samples are highlighted, and how-to guidance is more easily navigated with an eye toward the development lifecycle. &lt;/li&gt;    &lt;li&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211360.aspx" target="_blank"&gt;One Dev Minute&lt;/a&gt;” videos throughout the site, which give you a quick look at how to add features to your app. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Designers&lt;/h3&gt;  &lt;p&gt;We’ve overhauled the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh779072.aspx" target="_blank"&gt;Design section&lt;/a&gt; of the site to make it both easier to use and more comprehensive. You can find useful downloads and reusable design assets more easily, and design inspiration and case studies give you the tools you need to make a unique experience on Windows. Everything you need to build a beautiful app that stands out from the crowd is right at your fingertips, with a page design that’s touch-friendly and easy-to-use.&lt;/p&gt;  &lt;h3&gt;Businesses&lt;/h3&gt;  &lt;p&gt;The business opportunity of the Windows Store is significant, with a better economic model than competitive platforms and flexibility that enables you to build the business you want. The new &lt;a href="http://go.microsoft.com/fwlink/?LinkID=285998" target="_blank"&gt;Market section&lt;/a&gt; of the site provides great tips for marketing your apps, evaluating telemetry data, and passing app certification. We’ve learned a lot about how to make certification easier and have improved the content to help you breeze through the process.&lt;/p&gt;  &lt;p&gt;Of course, many of you fill multiple roles, and we think the new site organization supports that as well. From hobbyists to creative agencies to the largest enterprise software developers, the new site organization will help you achieve your creative and business vision with Windows.&lt;/p&gt;  &lt;h2&gt;There’s more to come, and we want your input&lt;/h2&gt;  &lt;p&gt;With &lt;a href="http://www.buildwindows.com"&gt;BUILD 2013&lt;/a&gt; a little more than a month away, there’s plenty to talk about. We’re working hard to produce new content to expand on what will be shared at this year’s event. In addition to keeping up with this blog, other ways to stay connected include following &lt;a href="https://twitter.com/#!/windevs" target="_blank"&gt;@windevs&lt;/a&gt; on Twitter and subscribing to the &lt;a href="http://www.windowsstore.com/newsletter-signup" target="_blank"&gt;Windows Store newsletter&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;As we roll out more content to help you design, develop, and market your Windows Store apps, we want to keep improving your Dev Center experience! To make it easier for you to tell us what you think, we’ve provided two new feedback options at the bottom of every page. Please provide feedback– we’re listening and are always working to address your concerns.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Keith Boyd, Content Publishing Manager, Windows Developer Content&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10418629" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/dev+center/">dev center</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/developer+info/">developer info</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/app+building/">app building</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+Store+apps/">Windows Store apps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/build/">build</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+Dev+Center/">Windows Dev Center</category></item><item><title>Sharing to your target app</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/05/08/sharing-to-your-target-app.aspx</link><pubDate>Wed, 08 May 2013 15:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10416470</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10416470</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/05/08/sharing-to-your-target-app.aspx#comments</comments><description>&lt;p&gt;In &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/12/12/sharing-from-your-app.aspx" target="_blank"&gt;Sharing from your app&lt;/a&gt;, we introduced the idea of sharing content from the example app &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/07/11/creating-metro-style-apps-that-stand-out-from-the-crowd.aspx" target="_blank"&gt;Food with Friends&lt;/a&gt; to several target apps that let the user accomplish rich end-to-end scenarios. Apps in Windows 8 offer interesting content that your customers will want to &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465251.aspx" target="_blank"&gt;share&lt;/a&gt; with friends or other apps. With a compelling and well-designed share target, your app can be at the heart of a social and connected experience for your customers.&lt;/p&gt;  &lt;p&gt;In this post we look at how you can use the Share target contract for your apps, especially those like Food with Friends. Using this contract, your app can &lt;i&gt;receive content&lt;/i&gt; from other apps and use that content to improve its quality. We want to help you make your app the best in its category!&lt;/p&gt;  &lt;p&gt;A target app is built using the Share target &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/03/23/activating-windows-8-contracts-in-your-app.aspx" target="_blank"&gt;contract&lt;/a&gt;&lt;u&gt;&lt;/u&gt; and is designed for a quick and easy sharing experience. Not every app in Windows will be a share target, but if your app can publish, transform, store or somehow add value to content it receives from another app, there are benefits to creating a Share target. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Your app will always show up in the target app list. It’s instantly relevant and connected to other apps that can share data you want. &lt;/li&gt;    &lt;li&gt;The share contract creates a bridge between your app and any source app without either app requiring one-to-one integration. &lt;/li&gt;    &lt;li&gt;Because the Share charm is always present and available in the OS, it gives your target app a presence in the OS that extends beyond the boundaries of your app. This can potentially point more customers to your app!&lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Receiving shared content&lt;/h2&gt;  &lt;p&gt;Let’s take a look at few examples that show how you can deliver compelling experiences through a Share target app.&lt;/p&gt;  &lt;p&gt;You might already be familiar with the Mail and People apps on Windows 8. Mail creates an easy and personal share target experience for receiving and sharing content with one or more friends. The People app lets you share content with broader audiences on your social networks. In addition to social sharing, you can go a step further with in app-to-app sharing. Productivity apps like SkyDrive can receive files from anywhere in Windows and store these on the cloud; note-taking apps can receive text, links and possibly data in a wide variety of other formats and archive it for reference later. There’s also plenty of room to get creative. &lt;/p&gt;  &lt;p&gt;Look at how the two pictures below show the share flow when sharing a photo from the Photos app to PuzzleTouch, a game app that turns the picture into a visual puzzle. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8637.puzzletouch1_5F00_6E4332DA.png"&gt;&lt;img title="Source app on the left; list of filtered target apps that can receive photos in the Share pane on the right. " style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Source app on the left; list of filtered target apps that can receive photos in the Share pane on the right. " src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1307.puzzletouch1_5F00_thumb_5F00_2681A9F3.png" width="700" height="394" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;i&gt;Figure 1: Source app on the left; list of filtered target apps that can receive photos in the Share pane on the right.      &lt;br /&gt;PuzzleTouch is one of the Share targets that can receive a picture from the Photos app. &lt;/i&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/6661.puzzletouch2_5F00_463083BB.png"&gt;&lt;img title="On the right, the target app preview lets the user select what type of puzzle they " style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="On the right, the target app preview lets the user select what type of puzzle they " src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/2474.puzzletouch2_5F00_thumb_5F00_65DF5D83.png" width="700" height="394" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;i&gt;Figure 2: On the right, the target app preview lets the user select what type of puzzle they      &lt;br /&gt;want to build. The puzzle is ready when the user switches back to the app. &lt;/i&gt;&lt;/p&gt;  &lt;h2&gt;What is a share target app?&lt;/h2&gt;  &lt;p&gt;An end-to-end sharing experience in Windows has two components. You have a source app that makes its content available in different formats to Windows. You also have a share target app that registers to recognize certain formats and act as the destination for the content being shared. Using the Share contract, the source app and the share target app communicate with each other.&lt;/p&gt;  &lt;p&gt;When you think about the share experience for your app, consider that the share target app is rendered in the hosted Share window. Make sure you design the experience so your user can quickly preview their content and confirm sharing in this view. This example shows the Mail share target app view that allows a user to quickly share a link from the browser with one of his or her mail contacts. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8561.Share_2D00_Target_2D00_Image_5F00_3ED44139.png"&gt;&lt;img title="Share Target Image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Share Target Image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/6011.Share_2D00_Target_2D00_Image_5F00_thumb_5F00_4FD86F1C.png" width="700" height="435" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;i&gt;Figure 3: Sharing a link from the Photos app using the Mail target app&lt;/i&gt;&lt;/p&gt;  &lt;h2&gt;Scenarios for Food with Friends&lt;/h2&gt;  &lt;p&gt;Now, let’s consider how &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/07/11/creating-metro-style-apps-that-stand-out-from-the-crowd.aspx" target="_blank"&gt;Food with Friends&lt;/a&gt; creates a compelling Share target app experience. If you’re familiar with the app, you’ll see two main actions that a user can take in Food with Friends – &lt;i&gt;creating a plan&lt;/i&gt; and &lt;i&gt;adding a restaurant to their Wishlist&lt;/i&gt;. Of course, there are other actions such as writing a review, posting a comment, viewing your friends’ wish lists, and so on, but those experiences make sense within the context of the main app. For the two core scenarios that stand out, let’s do a quick sanity-check to see if these can be effectively completed via the Food with Friends target app.&lt;/p&gt;  &lt;h3&gt;Create Tonight’s plan&lt;/h3&gt;  &lt;p&gt;While a core scenario of the main app, this isn’t the best scenario for a Share target experience. Here’s why: The Share target experience is meant to be quick and easy. Creating a plan is a much more involved task – a user would want to know what other restaurants her friends want to try out, compare a few restaurants from their Wishlist, review ratings and so on. Because planning involves leveraging details that are best presented in the main app view, condensing that functionality into the Share target app is not compelling. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;h3&gt;Add to Wishlist&lt;/h3&gt;  &lt;p&gt;This scenario works really well as a short and directed task in the Share target. Some highlights in this app experience:&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;People come across restaurants in other apps, whether these are trip planning apps, local city apps with recommendations, food blogs, and so on. Food with Friends is a great destination for aggregating restaurants in the ‘My Wishlist’ section. &lt;/li&gt;    &lt;li&gt;The target app view of an app is designed for a user to quickly take action while in the context of a different app. Thus, adding a restaurant to a Wishlist is an excellent option to surface in the Share target. &lt;/li&gt;    &lt;li&gt;While it’s certainly possible for the user to switch apps, repeat the search to find the restaurant, and then add the restaurant to their Wishlist, it’s a much easier experience to quick tap on Share.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The Food with Friends Wishlist seems to be a great share target app experience that we want to design and build. Here’s the end-to-end scenario we have in mind:&lt;/p&gt;  &lt;p&gt;While browsing an app that shows me local food trucks, I find a food truck recommendation that sounds interesting. I want to add the food truck from this app to My Wishlist in Food with Friends to help with planning later.&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7658.contoso_5F00_truck_5F00_6C263411.png"&gt;&lt;img title="Browsing an app that shows local food trucks and recommends places of interest" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Browsing an app that shows local food trucks and recommends places of interest" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3022.contoso_5F00_truck_5F00_thumb_5F00_4B9EF45F.png" width="700" height="394" /&gt;&lt;/a&gt;&lt;em&gt;Figure 4: Browsing an app that shows local food trucks and recommends places of interest&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;This image shows the share target app view that we want to use:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3835.contoso_5F00_truck2_5F00_565C4BB4.png"&gt;&lt;img title="The share target app view" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="The share target app view" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8637.contoso_5F00_truck2_5F00_thumb_5F00_760B257C.png" width="700" height="394" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;em&gt;Figure 5: The share target app view&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;By completing the share action in the target app view, users can curate restaurants in Food with Friends, without switching context from their current immersive app experience. &lt;/p&gt;  &lt;h2&gt;Implementing a share target&lt;/h2&gt;  &lt;p&gt;Now that you’ve seen some examples of when to implement a share target, let’s look at how you implement a share target. First, decide which data formats your app can receive. &lt;/p&gt;  &lt;h3&gt;Which data formats should you support?&lt;/h3&gt;  &lt;p&gt;With Share you can support either standard data formats such as text, URI, HTML, bitmaps, files or custom data formats such as the ones listed on &lt;a href="http://schema.org" target="_blank"&gt;http://schema.org&lt;/a&gt; . Windows filters target apps by the data formats they support to display the filtered target app list in the Share pane. Your app should support data formats that are important to the app experience. For example, if your app is about viewing photos, supporting text formats might not be helpful. If you declare support for multiple data formats, decide which one helps you represent the shared data best so you can pick that format from the data package first. &lt;/p&gt;  &lt;p&gt;Since Food with Friends is implementing a share target experience that lets users share restaurants to the app, we’ll use the &lt;a href="http://schema.org/Restaurant" target="_blank"&gt;Restaurant&lt;/a&gt;&lt;u&gt;&lt;/u&gt; data format listed on &lt;a href="http://schema.org" target="_blank"&gt;http://schema.org&lt;/a&gt;. Food with Friends can register with the Share target contract to receive this data format. Then, using the data in the received package, it can build a compelling experience in its target app view that allows the user to add that restaurant to their Wishlist. &lt;/p&gt;  &lt;p&gt;While some source apps may specifically share out the &lt;a href="http://schema.org/Restaurant" target="_blank"&gt;Restaurant&lt;/a&gt;&lt;u&gt;&lt;/u&gt; data format, other source apps may represent similar information using other data formats like &lt;a href="http://schema.org/Place" target="_blank"&gt;Place&lt;/a&gt;&lt;u&gt;&lt;/u&gt;, &lt;a href="http://schema.org/LocalBusiness" target="_blank"&gt;LocalBusiness&lt;/a&gt;&lt;u&gt;&lt;/u&gt; and &lt;a href="http://schema.org/FoodEstablishment" target="_blank"&gt;FoodEstablishment&lt;/a&gt; listed on &lt;a href="http://schema.org/" target="_blank"&gt;schema.org&lt;/a&gt;&lt;u&gt;&lt;/u&gt;. Thus, Food with Friends can support receiving multiple formats in the share contract to cater to a wider variety of source apps.&lt;/p&gt;  &lt;p&gt;Food with Friends supports the following formats in the Share target declarations of the app manifest:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;u&gt;&lt;a href="http://schema.org/Restaurant" target="_blank"&gt;Restaurant&lt;/a&gt;&lt;/u&gt;&lt;/li&gt;    &lt;li&gt;&lt;u&gt;&lt;a href="http://schema.org/Place" target="_blank"&gt;Place&lt;/a&gt;&lt;/u&gt;&lt;/li&gt;    &lt;li&gt;&lt;u&gt;&lt;a href="http://schema.org/LocalBusiness" target="_blank"&gt;LocalBusiness&lt;/a&gt;&lt;/u&gt;&lt;/li&gt;    &lt;li&gt;&lt;u&gt;&lt;a href="http://schema.org/FoodEstablishment" target="_blank"&gt;FoodEstablishment&lt;/a&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;We’re focusing on the &lt;a href="http://schema.org/Restaurant" target="_blank"&gt;Restaurant&lt;/a&gt;&lt;u&gt;&lt;/u&gt; data type for the sake of brevity, but the concepts apply to other data types as well.&lt;/p&gt;  &lt;h3&gt;Which data formats and scenarios should you scope out? &lt;/h3&gt;  &lt;p&gt;Food with Friends will only support adding the restaurant to the user’s Wishlist if the restaurant information received matches that of a restaurant that the app is already aware of. This is intentional to avoid multiple copies of restaurants in the app. &lt;/p&gt;  &lt;p&gt;We’re not supporting standard data types because most text, files, photos, URI or HTML shared from source apps won’t be mapped to a restaurant or local business. For example, if Food with Friends supported receiving text, it would show up in the target app list for a notetaking source app. In this case, Food With Friends would need to provide an error message telling the user why this app doesn’t work with their source app. Bottom line, the data formats are what connect a source app that has something to offer a target app. If the data formats aren’t the same, there’s nothing worthwhile to share.&lt;/p&gt;  &lt;p&gt;Make sure you consider all data formats that help identify what you care about, scope out the data formats that dilute your share experience.&lt;/p&gt;  &lt;h3&gt;Supporting the Share target contract&lt;/h3&gt;  &lt;p&gt;To support data formats, declare them in the Visual Studio manifest designer for your app. This is what happens when a user selects your app as the target of a share action:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;A new instance of the app is launched in the share target window over the source app. &lt;/li&gt;    &lt;li&gt;A &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.sharetargetactivatedeventargs.aspx" target="_blank"&gt;share target activation&lt;/a&gt; event is fired and your app receives a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br205977.aspx" target="_blank"&gt;ShareOperation&lt;/a&gt;&lt;b&gt;&lt;/b&gt; object as a result.&lt;/li&gt;    &lt;li&gt;Your app can retrieve the data that the user shared from this object. &lt;/li&gt;    &lt;li&gt;You can use this data to render the target app view and complete the user’s share. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;For more info about how to create this experience, see the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465255.aspx" target="_blank"&gt;Receiving shared content&lt;/a&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465255.aspx"&gt;&lt;u&gt;Quickstart&lt;/u&gt;&lt;/a&gt; guide. &lt;/p&gt;  &lt;p&gt;Additionally, Visual Studio supports a template for share targets. Right-click your project, select &lt;b&gt;Add Item&lt;/b&gt;, &lt;b&gt;Add New Item&lt;/b&gt;, click &lt;b&gt;Share Target Contract&lt;/b&gt; from the list and you get code added for supporting the contract. The &lt;a href="http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782" target="_blank"&gt;Share target code sample&lt;/a&gt;&lt;u&gt;&lt;/u&gt; shows how to receive shared content.&lt;/p&gt;  &lt;h2&gt;Designing a tailored target app view&lt;/h2&gt;  &lt;p&gt;When the user selects a target app from the list of apps in the Share pane, Windows launches the app in the app’s share target view. The target app view is a special view hosted in the Share pane and is different from the app’s main view. &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/03/23/activating-windows-8-contracts-in-your-app.aspx" target="_blank"&gt;Activating Windows 8 contracts in your app&lt;/a&gt;&lt;u&gt;&lt;/u&gt; gives more info about hosted views and handling activation for these views. The target app view is designed to help complete the share action initiated by the user. In this view, users should be able to preview their content at a glance, take simple actions, and confirm their intent to share. &lt;/p&gt;  &lt;p&gt;Before we look at the target app design for Food with Friends, let’s consider a target app that you might already know. The images below show the target app view for the Mail app alongside the full view of the app in &lt;a&gt;&lt;/a&gt;Windows 8.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1307.target_2D00_app_5F00_4AC68E75.png"&gt;&lt;img title="Sharing from Photos to the Mail target app on the right" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Sharing from Photos to the Mail target app on the right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0724.target_2D00_app_5F00_thumb_5F00_5583E5CA.png" width="700" height="438" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;i&gt;Figure 6: Sharing from Photos to the Mail target app on the right&lt;/i&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1385.mail_5F00_154DCC50.png"&gt;&lt;img title="Composing a new mail in the main app view of Mail" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Composing a new mail in the main app view of Mail" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/2055.mail_5F00_thumb_5F00_510D6503.png" width="700" height="438" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;em&gt;Figure 7: Composing a new mail in the main app view of Mail&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Notice that Mail’s share target app view is simpler than its full app view. It provides a clean and minimal preview of the content the user is about to share in the form of a thumbnail and associated text and HTML. It provides a &lt;b&gt;To&lt;/b&gt; line for adding recipients, an input area for composing a quick message and an easy to way to confirm sending the mail through the &lt;b&gt;Send&lt;/b&gt; button.&lt;/p&gt;  &lt;p&gt;Despite this simpler view, the app’s target app view is clearly identifiable as an avatar of the Mail app, which reinforces user confidence about the destination of the shared content.&lt;/p&gt;  &lt;h2&gt;Food with Friends as a share target app&lt;/h2&gt;  &lt;p&gt;Now that you have a general idea about design for the target app view, let’s discuss how Food with Friends can create a target app helps users add restaurants to the ‘My Wishlist.’ &lt;/p&gt;  &lt;p&gt;When Food with Friends receives the data package containing a &lt;a href="http://schema.org/Restaurant"&gt;Restaurant&lt;/a&gt; from the source app, it can use the details in the &lt;a href="http://schema.org/Restaurant"&gt;Restaurant&lt;/a&gt; data format to identify which restaurant from its existing database matches the received data package. The app can then show a preview of this restaurant in the target app view. This reinforces confidence in the integrity of the content being shared. &lt;/p&gt;  &lt;p&gt;This image shows the target app view for Food with Friends –&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3857.contoso_5F00_truck3_5F00_0305058E.png"&gt;&lt;img title="The target app view for Food with Friends" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="The target app view for Food with Friends" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/5584.contoso_5F00_truck3_5F00_thumb_5F00_1B94A2DE.png" width="700" height="394" /&gt;&lt;/a&gt;&lt;em&gt;Figure 8: The target app view for Food with Friends&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;As you can see this view of Food with Friends is simple and tailored for a share target app - It shows a preview of the restaurant that the user is about to share and a simple actionable button, &lt;b&gt;Add to Wishlist&lt;/b&gt; that clarifies the destination of the shared content in the main app. When the user taps or clicks this button, it confirms the share operation. By requiring a tap or click here, we help prevent accidental sharing and build confidence in the overall Share experience. &lt;/p&gt;  &lt;p&gt;If the app finds multiple restaurants that match the info of the data package content, Food with Friends uses the share target app view to show the options and let the user pick which ones to share. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/5582.contoso_5F00_truck4_5F00_70500BD6.png"&gt;&lt;img title="Target app view shows options so users can pick which items to share" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Target app view shows options so users can pick which items to share" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/6175.contoso_5F00_truck4_5F00_thumb_5F00_6FE3D8E1.png" width="700" height="394" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;em&gt;Figure 9: Target app view shows options so users can pick which items to share&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In case the app cannot accurately identify a restaurant or a valid set of options based on the received data package, use the target app view to communicate that message. &lt;/p&gt;  &lt;h2&gt;Creating a QuickLink&lt;/h2&gt;  &lt;p&gt;A &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.sharetarget.quicklink.aspx" target="_blank"&gt;QuickLink&lt;/a&gt; is a provision of the Share API that lets users share content to familiar destinations within your target app quickly. A QuickLink acts as a customized link to your target view, providing specific actions. When Windows filters the list of target apps available to the user, the list of QuickLinks is featured at the top of the Share pane as the list of available targets. These familiar destinations or user actions may include places or people that are shared with often through the target app. For example, the Mail app returns QuickLinks for previously mailed contacts. Similarly, you can add QuickLinks to folders, groups, notebooks, and playlists that you share often to your target app. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/5001.quicklink_5F00_2FADBF67.png"&gt;&lt;img title="Share pane shows a QuickLink provided by the Mail target app for contacts " style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Share pane shows a QuickLink provided by the Mail target app for contacts " src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1374.quicklink_5F00_thumb_5F00_334BDA44.png" width="700" height="438" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;i&gt;Figure 10: Share pane shows a QuickLink provided by the Mail target app for contacts      &lt;br /&gt;that have been previously mailed using the target app&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;The target app can provide a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.sharetarget.quicklink.aspx" target="_blank"&gt;QuickLink&lt;/a&gt;&lt;u&gt;&lt;/u&gt; by calling &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br205977.aspx" target="_blank"&gt;ShareOperation&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;b&gt;&lt;u&gt; &lt;/u&gt;&lt;/b&gt;objects’&lt;b&gt;&lt;u&gt; &lt;/u&gt;&lt;/b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.sharetarget.shareoperation.reportcompleted.aspx" target="_blank"&gt;reportCompleted&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;u&gt; &lt;/u&gt;&lt;/b&gt;method. A QuickLink must have a title, an icon, and an ID. The title (like &amp;quot;Email Mom&amp;quot;) and icon appear when the user taps the Share charm. The ID is what your app uses to access any custom information, such as an email address, a folder location and so on. See &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh758299.aspx" target="_blank"&gt;How to Create a QuickLink&lt;/a&gt;&lt;u&gt;&lt;/u&gt; to learn more about this tool.&amp;#160; &lt;/p&gt;  &lt;p&gt;Note: QuickLinks are useful when the app supports multiple actions from the target app. Because Food with Friends only supports a single action in the Share target i.e. &lt;b&gt;Add to Wishlist&lt;/b&gt;, the app doesn’t implement QuickLinks. &lt;/p&gt;  &lt;h2&gt;Extended share and error reporting&lt;/h2&gt;  &lt;p&gt;Sometimes source apps share large chunks of data like photos, videos, or files resulting in longer data transfer times. These types of share operations are known as &lt;i&gt;extended shares&lt;/i&gt; where your target app might need more time to receive and process the data. &lt;/p&gt;  &lt;p&gt;Because sharing is to be fast and fluid and the target app view is a lightweight, hosted view over the main app, users might tap away from the target app view to get back to their main app. Thus, target apps shouldn’t rely on or expect user interaction with the target app view after sharing has begun. Target apps can rely on using the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br205977.aspx" target="_blank"&gt;ShareOperation&lt;/a&gt;&lt;b&gt;&lt;/b&gt; object and its methods to let Windows know that the app is processing data. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.sharetarget.shareoperation.reportstarted.aspx" target="_blank"&gt;reportStarted&lt;/a&gt;&lt;/b&gt; – call this method to let Windows know your app has started retrieving the data in the DataPackage object from the source app. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.sharetarget.shareoperation.reportdataretrieved.aspx" target="_blank"&gt;reportDataRetrieved&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;u&gt; &lt;/u&gt;&lt;/b&gt;– call this method to let Windows know your app has finished retrieving the data in the package.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.sharetarget.shareoperation.reportcompleted.aspx" target="_blank"&gt;reportCompleted&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;u&gt; – &lt;/u&gt;&lt;/b&gt;call this method to let Windows know your app has completed the Share operation.&lt;b&gt;&lt;u&gt; &lt;/u&gt;&lt;/b&gt;&lt;b&gt;&lt;u&gt;&lt;/u&gt;&lt;/b&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;When your app is processing data for an extended share, give the user a progress UI in the target app view. This informs the user that their request is underway and reinforces confidence when they return to your app and check on the progress of the share operation. Check out &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465487.aspx" target="_blank"&gt;Quickstart: adding progress controls&lt;/a&gt;&lt;u&gt;&lt;/u&gt; to learn more about progress controls in Windows 8. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0702.progress_2D00_bar_5F00_52FAB40C.png"&gt;&lt;img title="progress bar" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="progress bar" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3438.progress_2D00_bar_5F00_thumb_5F00_40B1ED4A.png" width="700" height="438" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;i&gt;Figure 11: Mail target app view shows a progress ring when completing an extended share such as sending over large attachments&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;If something goes wrong during the data transfer and your target app has to end the share operation, you can call &lt;b&gt;&lt;u&gt;reportError&lt;/u&gt;&lt;/b&gt; to send an error message to Windows. The user will see the message when they check status of the share in the Share pane. After you report the error, your app is shut down and the share is ended. The user will need to start again to share the content to your app.&lt;/p&gt;  &lt;p&gt;In the Food with Friends share target example, if the app cannot identify a restaurant in its database that matches the restaurant that was shared from the source app via the &lt;a href="http://schema.org/Restaurant" target="_blank"&gt;Restaurant&lt;/a&gt;&lt;u&gt;&lt;/u&gt; data format, the app should report an error. &lt;/p&gt;  &lt;h2&gt;Let’s review!&lt;/h2&gt;  &lt;p&gt;App-to-app sharing provides a great opportunity to share target apps. By enabling your app to receive shared content, your users get value from your app even when they are involved in another activity. We hope you have a better understanding of the design principles as well data types, classes and properties that you can use to create a great share target destination. We’re excited to discover how your apps will transform shared content and create broader and richer end-user experiences.&lt;/p&gt;  &lt;p&gt;If you want to learn more about sharing, read &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464923.aspx" target="_blank"&gt;Sharing and Exchanging Data&lt;/a&gt;&lt;u&gt;&lt;/u&gt; and the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782" target="_blank"&gt;Share content target app sample&lt;/a&gt;&lt;u&gt;&lt;/u&gt; to get started!&lt;/p&gt;  &lt;p&gt;Ishita Kapur&lt;/p&gt;  &lt;p&gt;Program Manager&lt;/p&gt;  &lt;p&gt;Windows User Experience&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10416470" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/sharing+apps/">sharing apps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/target+apps/">target apps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/shared+content/">shared content</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/share+target/">share target</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/sharing+target+apps/">sharing target apps</category></item><item><title>Develop a cutting edge app with NFC</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/18/develop-a-cutting-edge-app-with-nfc.aspx</link><pubDate>Thu, 18 Apr 2013 22:25:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10412390</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10412390</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/18/develop-a-cutting-edge-app-with-nfc.aspx#comments</comments><description>&lt;p&gt;Near Field Communication (NFC) is an emerging, short range wireless technology. With a precise range of 2 cm, people can physically tap devices together to send/receive content. Tapping lets you select something (or someone) quickly. Not only is it quick, it’s also easy to understand. Once you see it, you get it; there’s no manual needed.&lt;/p&gt;  &lt;p&gt;For example, imagine you are looking at some photos with a friend and she wants your pictures; with NFC, you can simply tap your device against her PC to send the photos. Over simplifying? Maybe, but the main idea is that it’s simple to share content between devices.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1732.NFC_2D00_image_5F00_04E645BB.png"&gt;&lt;img title="&amp;#39;This image shows the Nokia 360 speaker sharing its Bluetooth pairing information with a Windows Phone" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="&amp;#39;This image shows the Nokia 360 speaker sharing its Bluetooth pairing information with a Windows Phone" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3566.NFC_2D00_image_5F00_thumb_5F00_38420917.png" width="400" height="348" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;Figure 1: This image shows the Nokia 360 speaker sharing its Bluetooth    &lt;br /&gt;pairing information with a Windows Phone&lt;/p&gt;  &lt;p&gt;Similar to Bluetooth or Wi-Fi, NFC is a standard wireless protocol defined by the &lt;a href="http://www.nfc-forum.org/home/" target="_blank"&gt;NFC Forum&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;u&gt;. &lt;/u&gt;Your PC needs an NFC radio. There are lots of Windows 8 PCs that have NFC radios integrated directly into them. If NFC isn’t already part of your PC, you can buy NFC dongles to plug into your PC.&lt;/p&gt;  &lt;p&gt;NFC offers some cool capabilities. People can tap and send photos, tap a menu and order a meal at a restaurant, or even tap to pair a Bluetooth device.&amp;#160; These scenarios are pretty different from each other, but the thing they have in common is the 'tap' to initiate the experience.&amp;#160; NFC is used in variety of devices, such as PCs, phones, speakers, headsets, wireless displays, etc..., to make connecting devices together a really intuitive experience.&amp;#160; Also, NFC uses RFID tags; these are really cheap, lightweight passive antennas that can hold a sizable amount of data and can be stuck on virtually anything, most commonly posters.&amp;#160; For example, buying a movie ticket could be as simple as tapping the movie poster!&amp;#160; These are called NFC tags.&amp;#160; We'll walk through a basic example of tapping an NFC tag to demonstrate some key concepts of the NFC API.&lt;/p&gt;  &lt;p&gt;But first, let’s take a closer look at what it means to tap devices together.&lt;/p&gt;  &lt;h2&gt;Defining a ‘Tap’&lt;/h2&gt;  &lt;p&gt;Whether you’re tapping to pair a Bluetooth mouse or tapping to share photos, it’s important for users to tap devices together the same way. And while tapping is a well understood concept, tapping your PC against another device is new to most people. Here are some guidelines for tapping that let users know:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div align="center"&gt;&lt;b&gt;Where to tap devices together&lt;/b&gt; – by using a touchmark, also known as the ‘Tap and Do’ visual mark, indicating where the NFC antenna is located. Depending on the PC model, you tap different parts of the PC. For example, you may tap on the back on a tablet but on the front an all-in-one. Here’s what the mark looks like on any NFC enabled, Windows 8 PC:         &lt;br /&gt;&lt;/div&gt;     &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0830.NFC_2D00_logo_5F00_66E85720.png"&gt;&lt;img title="Tap and Do visual mark" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Tap and Do visual mark" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/5611.NFC_2D00_logo_5F00_thumb_5F00_3FAE0DEB.png" width="200" height="147" /&gt;&lt;/a&gt;      &lt;p align="center"&gt;Figure 2: Tap and Do visual mark&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Devices are communicating with each other&lt;/b&gt; - During the tap, users should have confidence that something is going on; even if they can’t see the data being transferred. Therefore, Windows plays a sound when devices are in-range and communicating with each other.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Windows does these things automatically, so you won’t need to worry about them. For more info on these user experience elements, see the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/hardware/hh770524.aspx" target="_blank"&gt;Windows 8 Near Field Proximity Implementation Specification&lt;/a&gt;&lt;u&gt;&lt;/u&gt;. With that in mind, let's check out some of the cool scenarios you can experience with NFC.&lt;/p&gt;  &lt;h2&gt;When to use NFC &lt;/h2&gt;  &lt;p&gt;Use NFC when a user needs to select something, or someone, in your app. NFC gives you an intuitive way to select; and it’s often faster (and cooler!) than manually searching. The tap is a trigger to initiate an experience; and depending on your app, the experience can range from receiving a photo to starting a playlist. It’s really up to your app to decide what happens after the tap. So, to keep it simple, we classify this range of experiences as ‘Tap and Do’ experiences.&lt;/p&gt;  &lt;p&gt;Below are a few examples of using NFC to select something in an app. You could Tap and…&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;u&gt;Get information from a poster&lt;/u&gt;: &lt;a href="http://www.nfc-forum.org/news/pr/view?item_key=2c0cb92de7d47bbbe7c99f13912b3307fc03c1c6" target="_blank"&gt;NFC tags&lt;/a&gt; are light, cheap RFID tags; they cost between $0.15 - $1.00 (price varies on printing cost). These are comparable to QR codes, but are easier and faster to use.&amp;#160; Tapping a tag feels more comfortable than taking a picture of the bar code (and hoping the camera got the right angle).&amp;#160; Manufacturers are increasingly embedding tags into posters in high traffic areas like airports, metro stations, and bus stops. They can hold between 48 B – 4 KB of data. You can program a tag to launch your app to a specific page. &lt;/li&gt; &lt;/ul&gt;  &lt;ul&gt;   &lt;li&gt;E&lt;u&gt;xchange contact information&lt;/u&gt;: instead of spelling out your contact information to a friend, and hoping he didn’t misspell anything, tap devices together to exchange contact information. Similar to above, you can program your information to an NFC-business card/tag; or you could directly exchange information via an app.&lt;/li&gt;    &lt;li&gt;&lt;u&gt;Play your favorite music station&lt;/u&gt;: whether you’re about to go work out, hopping into your car or just lounging at home – use an NFC tag to start a radio station. You can even have different music stations programmed on different tags; for example, one tag for the gym, one for lounging, and one for sleep.&lt;/li&gt;    &lt;li&gt;&lt;u&gt;Order dinner at a busy restaurant&lt;/u&gt;: a popular restaurant at dinner time means you might be waiting a long time just to place an order. Instead, tap a tag at your table to order your food.&lt;/li&gt;    &lt;li&gt;&lt;u&gt;Play a multiplayer game with a friend: &lt;/u&gt;you can easily connect a multiplayer game like Battleship, Chess, or Scrabble with a friend by tapping devices together. After the tap, the connection persists over an out-of-band transport with a bigger range and higher throughput, such as Bluetooth or Wi-Fi Direct. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;By now, we’ve got a pretty good idea of when to use NFC; now for fun stuff – building an app that uses our Windows 8 Proximity (NFC) APIs.&lt;/p&gt;  &lt;h2&gt;How to implement NFC &lt;/h2&gt;  &lt;p&gt;As you can see NFC makes lots of everyday tasks easier for end-users. Take setting an alarm for example. I’m sure just about everyone has had a few experiences where they mistakenly set their alarm for the wrong time in the morning. When its late and you just want to get to sleep, you’re not always thinking at your best. NFC makes this easier by letting you just tap a preset tag, confirm, and then go to sleep worry free. So to help users with this everyday task let’s imagine you wrote a basic alarm app that let users set an alarm using an NFC tag. This breaks into two scenarios&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;u&gt;Setting an alarm &lt;b&gt;on&lt;/b&gt; the tag&lt;/u&gt;: NFC tags can be reusable, so the app should have a way for users to program an alarm. For example, a user may want to program different alarms – one for the week, another for the weekend. This is known as publishing data to a tag.&lt;/li&gt;    &lt;li&gt;&lt;u&gt;Setting an alarm &lt;b&gt;from&lt;/b&gt; the tag&lt;/u&gt;: After a user taps a tag, the app should launch to confirm setting an alarm. This means the app can be launched with context, or arguments. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The NFC API allows for several ways to achieve the same thing, but I’ll go over the simplest way to implement this scenario.&lt;/p&gt;  &lt;p&gt;Let’s walk through a flow to set an alarm on an NFC tag:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Mario launches the alarm app and sets a time, say 7.00 AM. Normal alarm stuff, nothing with NFC yet.&lt;/li&gt;    &lt;li&gt;Mario selects an option to ‘Set alarm on an NFC tag’. At this time, the app calls the NFC APIs to publish information to the NFC radio, specifically an app identifier string &amp;amp; 07:00. NFC tags use a standardized message format called NDEF, NFC Defined Exchange Format. Your app does &lt;b&gt;not &lt;/b&gt;need to worry about formatting data into an NDEF message; Windows does this for you! Now, the user can tap the NFC tag.&lt;/li&gt;    &lt;li&gt;Mario taps the tag against the PC and the app confirms programming the tag. After the tag is tapped, it’s important to let users know that your app successfully programmed the tag. As we discussed earlier – tapping your PC is a new concept for most people, so the confirmation gives users confidence that what they just did worked. The app knows a message was successfully transmitted by registering for a message transmitted handler.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The NFC APIs are located in the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.proximity.aspx" target="_blank"&gt;Windows.Networking.Proximity&lt;/a&gt; namespace. They come into play at step 2 – after the user selects the option to ‘Set alarm on NFC tag.’ First, the app initializes a proximity object. The proximity object is used to tell when a tag (or device) is in/out of range. Next, we’ll add the DeviceArrival event handler. The handler recognizes when the tag has been tapped, which means we can start writing information to the tag. It’s useful to let users know when you’re writing to a tag, so they don’t move it out of range. You can use the same event to recognize when any proximity device has been tapped.&lt;/p&gt;  &lt;p&gt;The next code snippet shows how to initialize and add a DeviceArrival event handler.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;div&gt;     &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; proximityDevice;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; initializeProximityDevice() {&lt;br /&gt;    proximityDevice = Windows.Networking.Proximity.ProximityDevice.getDefault();&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (proximityDevice) {&lt;br /&gt;        proximityDevice.addEventListener(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;devicearrived&amp;quot;&lt;/span&gt;, proximityDeviceArrived);&lt;br /&gt;       &lt;br /&gt;}&lt;br /&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// No NFC radio on the PC, display an error message&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; proximityDeviceArrived(device) {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Let the user know we’re ‘Writing to Tag’&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; InitializeProximityDevice()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Windows.Networking.Proximity.ProximityDevice proximityDevice;&lt;br /&gt;    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (proximityDevice != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;) {&lt;br /&gt;        proximityDevice.DeviceArrived += ProximityDeviceArrived;&lt;br /&gt;    &lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// No NFC radio on the PC, display an error message&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; ProximityDeviceArrived(Windows.Networking.Proximity.ProximityDevice device)&lt;br /&gt;{&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// Let the user know we’re ‘Writing to Tag’&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;
  &lt;br /&gt;Next, we publish information to the tag. The app publishes two things: an app identifier string, which consists of an app ID and app platform, and launch arguments. For Windows 8, the app Id is &amp;lt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.packageid.familyname.aspx" target="_blank"&gt;package family name&lt;/a&gt;&amp;gt;!&amp;lt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211415.aspx" target="_blank"&gt;app Id&lt;/a&gt;&amp;gt; and the app platform is ‘Windows.’ You must copy the app ID value from the ID attribute of the Application element in the package manifest for your app. The launch argument is ’07:00’ – the alarm set by the user. Let’s call this the &lt;b&gt;message&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;If the app works across platforms, Windows lets you publish alternate app ID(s) and app platform(s); which means you can tap the same tag on a different device which support NFC, like Windows Phone 8! You can find more information about &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.proximity.peerfinder.alternateidentities.aspx" target="_blank"&gt;Alternate IDs&lt;/a&gt; on MSDN.&lt;/p&gt;

&lt;p&gt;The app publishes the data to the tag using a method called &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh701134.aspx" target="_blank"&gt;publishBinaryMessage&lt;/a&gt;. The method takes three parameters – messageType, message, and a messageTransmittedHandler function. We’ll set messageType to ‘LaunchApp:WriteTag’, which lets Windows know that your app wants to write information to an NFC tag. The message is just the message we defined earlier (app identified string and launch arguments); we’ll need to store the message as a binary message in a buffer. The messageTransmittedHandler function registers for callbacks. This lets your app know that the message has successfully been written to the tag. We’ll use this to tell the user two things: we’ve successfully written a message to the tag and the tag no longer needs to be in range.&lt;/p&gt;

&lt;p&gt;Messages continue to be published until we call the StopPublishingMessage function or the ProximityDevice object is released. In this example, we’ll use the stop function. PublishBinaryMessage returns a publication ID; we’ll use this same publication ID to stop publishing the message onto the NFC Radio.&lt;/p&gt;

&lt;p&gt;The next code snippet shows how to write data to an NFC tag:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; proximityDevice;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; getAlarmTime(){&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Grab time set by the user, call this variable ‘Alarm’&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Alarm;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; publishLaunchApp() {&lt;br /&gt;    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (proximityDevice) {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The format of the app launch string is: &amp;quot;&amp;lt;args&amp;gt;\tWindows\t&amp;lt;AppName&amp;gt;&amp;quot;.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The string is tab or null delimited.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The &amp;lt;args&amp;gt; string can be an empty string (&amp;quot;&amp;quot;).&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; launchArgs = getAlarmTime();&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The format of the AppName is: PackageFamilyName!PRAID.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; praid = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;AlarmApp&amp;quot;&lt;/span&gt;; &lt;span style="color: rgb(0, 128, 0);"&gt;// The Application Id value from your package.appxmanifest.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; appName = Windows.ApplicationModel.Package.current.id.familyName + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;!&amp;quot;&lt;/span&gt; + praid;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; launchAppMessage = launchArgs + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;\tWindows\t&amp;quot;&lt;/span&gt; + appName;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; dataWriter = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Windows.Storage.Streams.DataWriter();&lt;br /&gt;        dataWriter.unicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE;&lt;br /&gt;        dataWriter.writeString(launchAppMessage);&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; launchAppPubId =&lt;br /&gt;             proximityDevice.publishBinaryMessage(&lt;br /&gt;                 &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;LaunchApp:WriteTag&amp;quot;&lt;/span&gt;, &lt;br /&gt;                 dataWriter.detachBuffer(), &lt;br /&gt;                 proximityWriteTagLaunchAppMessageTransmitCallback);&lt;br /&gt;        &lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (launchAppPubId != -1) {&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// Stop publishing the message on NFC radio&lt;/span&gt;&lt;br /&gt;        proximityDevice.stopPublishingMessage(launchAppPubId);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; proximityWriteTagLaunchAppMessageTransmitCallback() {&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Inform the user that: the message has been successfully written to a tag &amp;amp; the tag no longer needs to be in range&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;Windows.Networking.Proximity.ProximityDevice proximityDevice;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; GetAlarmTime(){&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Grab time set by the user, call this variable ‘Alarm’&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Alarm;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; PublishLaunchApp()&lt;br /&gt;{&lt;br /&gt;    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (proximityDevice != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The format of the app launch string is: &amp;quot;&amp;lt;args&amp;gt;\tWindows\t&amp;lt;AppName&amp;gt;&amp;quot;.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The string is tab or null delimited.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The &amp;lt;args&amp;gt; string can be an empty string (&amp;quot;&amp;quot;).&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; launchArgs = getAlarmTime();&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// The format of the AppName is: PackageFamilyName!PRAID.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; praid = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;MyAppId&amp;quot;&lt;/span&gt;; &lt;span style="color: rgb(0, 128, 0);"&gt;// The Application Id value from your package.appxmanifest.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; appName = Windows.ApplicationModel.Package.Current.Id.FamilyName + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;!&amp;quot;&lt;/span&gt; + praid;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; launchAppMessage = launchArgs + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;\tWindows\t&amp;quot;&lt;/span&gt; + appName;&lt;br /&gt;&lt;br /&gt;        var dataWriter = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Windows.Storage.Streams.DataWriter();&lt;br /&gt;        dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE;&lt;br /&gt;        dataWriter.WriteString(launchAppMessage);&lt;br /&gt;        var launchAppPubId =&lt;br /&gt;        proximityDevice.PublishBinaryMessage(&lt;br /&gt;            &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;LaunchApp:WriteTag&amp;quot;&lt;/span&gt;, dataWriter.DetachBuffer(), &lt;br /&gt;            proximityWriteTagLaunchAppMessageTransmitCallback);&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (launchAppPubId!= -1)&lt;br /&gt;    {&lt;br /&gt;        proximityDevice.StopPublishingMessage(launchAppPubId);&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Stop publishing the message on NFC radio&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; proximityWriteTagLaunchAppMessageTransmitCallback(&lt;br /&gt;    Windows.Networking.Proximity.ProximityDevice sender,&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; messageId)&lt;br /&gt;{&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Inform the user that: the message has been successfully written to a tag &amp;amp; the tag no longer needs to be in range&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;br /&gt;That’s it! Now you know how to write to an NFC tag from a Windows Store app. Simple enough; so, let’s move onto the next scenario - setting an alarm &lt;b&gt;from&lt;/b&gt; the tag. Let’s walk through a flow to read an alarm from an NFC tag: 

&lt;ol&gt;
  &lt;li&gt;Mario is reading his home screen/writing an email/playing a game/using Windows and he realizes he needs to set an alarm for Monday morning. He grabs his ‘Weekday alarm’ tag and taps it on his PC. He gets a toast inviting him to launch your Alarm app. Windows takes care of everything up until this point; your app doesn’t do a thing.&lt;/li&gt;

  &lt;li&gt;Mario accepts and your app launches to a ‘Confirm Alarm?’ screen with a time of 7:00 AM. After Mario accepts the toast, Windows passes the launch arguments (same as above) to your app during activation. This is called contextual launching, which is the same thing as launching your app to specific page.&lt;/li&gt;

  &lt;li&gt;Mario sets the alarm. Normal alarm stuff, no NFC.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It’s easy enough to get the launch arguments from the NFC tag. The app needs to handle contextual launching from an NFC tag. Contextual launching is the synonymous with launching your app to a specific page. Our launch arguments specify an alarm, 7.00 AM, which your app uses to display a proposed alarm. Also, in case your app isn’t installed on the PC, Windows invites Mario to install your app from the Windows store – automatically!&lt;/p&gt;

&lt;p&gt;The following code snippet shows how to implement contextual launching.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;app.onactivated = &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (args) {&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (args.detail.kind === activation.ActivationKind.launch) {&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (args.detail.arguments == &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Windows.Networking.Proximity.PeerFinder:StreamSocket&amp;quot;&lt;/span&gt;) {&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;//do nothing here.&lt;/span&gt;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; {&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Use args.detail.arguments to parse out ’07.00’ string, and display to the user&lt;/span&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        args.setPromise(WinJS.UI.processAll());&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;async &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OnLaunched(LaunchActivatedEventArgs args)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (args.Arguments == &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Windows.Networking.Proximity.PeerFinder:StreamSocket&amp;quot;&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                _isLaunchedByTap = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Use args.Arguments to parse out ’07.00’ string, and display to the user&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;            Window.Current.Activate();&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;
  &lt;br /&gt;That’s all your app has to do to support reading and writing to an NFC tag; pretty simple for a cutting edge scenario. Before I wrap up, let’s go over some good hygiene stuff – error handling.&lt;/p&gt;

&lt;h2&gt;Error Handling&lt;/h2&gt;

&lt;p&gt;There are a few common errors your app may run into.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The tapped tag is not NDEF formatted. Windows 8 doesn’t support automatically reformatting a tag to NDEF, so you’ll need to download and install an NDEF formatter.&lt;/li&gt;

  &lt;li&gt;The tapped tag is read-only. Some NFC tags can be locked to read-only (similar to old school &lt;a href="http://en.wikipedia.org/wiki/VHS" target="_blank"&gt;VHS tapes&lt;/a&gt;).&lt;/li&gt;

  &lt;li&gt;The tapped tag is too small and cannot hold all the data.&lt;/li&gt;

  &lt;li&gt;A users PC doesn’t have NFC. As I mentioned from the start, NFC is an emerging technology; widespread adoption is still growing. To check whether a PC supports proximity, use the ProximityDevice.getDefault() method; the method returns NULL if no NFC radios are installed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;It’s fun and intuitive!&lt;/h2&gt;

&lt;p&gt;NFC is finally here, ready for mainstream consumers – Windows has the ecosystem and a well-designed end-to-end UX. The technology has a lot of potential to make apps and device experiences incredibly interactive. It’s fun and intuitive. &lt;/p&gt;

&lt;p&gt;NFC is a big area, so stay tuned for more blog posts on other cool Windows 8 NFC developer experiences.&lt;/p&gt;

&lt;p&gt;For more info about NFC and proximity, check out the resources below.&lt;/p&gt;

&lt;h2&gt;Resources&lt;/h2&gt;

&lt;div align="center"&gt;
  &lt;table class="b8table" cellspacing="0" cellpadding="3" width="298" align="center" border="0"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="197"&gt;
          &lt;p&gt;&lt;strong&gt;Link&lt;/strong&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="99"&gt;
          &lt;p&gt;&lt;strong&gt;Types&lt;/strong&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="197"&gt;
          &lt;p align="left"&gt;&lt;u&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465215.aspx" target="_blank"&gt;Guidelines for using proximity experiences&lt;/a&gt;&lt;/u&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="99"&gt;
          &lt;p&gt;Doc&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="197"&gt;
          &lt;p align="left"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br241250.aspx" target="_blank"&gt;Proximity APIs&lt;/a&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="99"&gt;
          &lt;p&gt;Doc&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="197"&gt;
          &lt;p align="left"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh967765.aspx" target="_blank"&gt;Testing and troubleshooting proximity apps&lt;/a&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="99"&gt;
          &lt;p&gt;Doc&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="197"&gt;
          &lt;p align="left"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465223.aspx" target="_blank"&gt;Publishing and subscribing (in further detail)&lt;/a&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="99"&gt;
          &lt;p&gt;Doc&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="197"&gt;
          &lt;p align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Proximity-Sample-88129731" target="_blank"&gt;Proximity app sample&lt;/a&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="99"&gt;
          &lt;p&gt;Sample&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="197"&gt;
          &lt;p align="left"&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-us/category/windowsapps" target="_blank"&gt;Got a question on proximity? Ask it here&lt;/a&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="99"&gt;
          &lt;p&gt;Forum&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;Priya Dandawate 
  &lt;br /&gt;Program Manager, Devices and Networking&lt;/p&gt;

&lt;p&gt;Contributions by: Max Morris, Marzena Makuta,&amp;#160; Mike Loholt, Jake Sabulsky, and Vishal Mhatre&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10412390" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/sharing/">sharing</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/NFC/">NFC</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Near+Field+Communication/">Near Field Communication</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/sharing+files/">sharing files</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Bluetooth+pairing/">Bluetooth pairing</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/sharing+data/">sharing data</category></item><item><title>Creating connected Windows Store apps</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/10/creating-connected-windows-store-apps.aspx</link><pubDate>Wed, 10 Apr 2013 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10409510</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10409510</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/10/creating-connected-windows-store-apps.aspx#comments</comments><description>&lt;p&gt;People are continually surrounded by devices that are connected to a network. Even the latest refrigerators and washing machines can connect to the internet and home networks. So it’s no surprise that end-users expect their apps to be connected as well. These “connected apps” consume the latest content from the web—social media, digital media, blogs, and other types of content. Developing connected apps has become the norm, but it can still be a challenge to handle common issues like loss of network connectivity, metered network costs, or performance issues. Windows 8 makes it easier than ever before to write a connected app. &lt;/p&gt;  &lt;p&gt;In this post, we’ll look at some useful tips to help you provide a fast and fluid, hassle-free, connected experience for users of your Windows Store apps: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Pick the right API for your scenarios&lt;/li&gt;    &lt;li&gt;Choose the right network capabilities&lt;/li&gt;    &lt;li&gt;Adapt app behavior for metered networks&lt;/li&gt;    &lt;li&gt;React to network status changes&lt;/li&gt;    &lt;li&gt;Cache content for fluidity&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Let’s dive into the details of each tip.&lt;/p&gt;  &lt;h2&gt;Pick the right API&lt;/h2&gt;  &lt;p&gt;If you're going to build a house, you want the right tools. You want a hammer for hammering nails, a saw for cutting boards, and a screwdriver for fastening with screws. In the same way, you’ll want to use the right networking APIs when you develop a connected Windows Store app. Windows 8 provides a variety of networking APIs that your app can use to communicate with other computers and devices over either the Internet or private networks. So your first step is to figure out what networking features your app needs. &lt;/p&gt;  &lt;p&gt;The most common networking scenario is to access a web site to retrieve or store information. A simple example would be a game that uses a website to store user information and game scores. A more complex example might be an app that connects to a REST-based web service and uses a library provided by the web service to access or store information. Windows 8 has several APIs that connect with web services and web sites. With these APIs your app can access web services that support REST or send basic HTTP protocol commands (like GET and POST) to a web server. For web access, the API you want depends on the language you use to develop the app:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453379.aspx" target="_blank"&gt;XMLHTTPRequest&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br229787.aspx" target="_blank"&gt;WinJS.xhr&lt;/a&gt;—Apps written in JavaScript and HTML.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx" target="_blank"&gt;HttpClient&lt;/a&gt;—Apps written in C# or Visual Basic .NET and XAML.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh831163.aspx" target="_blank"&gt;XML HTTP Request 2&lt;/a&gt; (IXHR2)—Apps written in C++ and XAML.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following code shows how to perform a basic request and response with a REST-based web service. In this case, the web service could execute an ASP.NET script on the web server.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;div id="codeSnippetWrapper"&gt;     &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; makeXHRCall() {&lt;br /&gt;    WinJS.xhr({ uri: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://www.microsoft.com/en-us/default.aspx” }).done(&lt;br /&gt;        function onComplete(result) {&lt;br /&gt;            print(result.responseText);&lt;br /&gt;        },&lt;br /&gt;        function onError(err) {&lt;br /&gt;            print(&amp;quot;&lt;/span&gt;Error: &amp;quot; + err.responseText);&lt;br /&gt;        });&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; async &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; MakeHttpCall()&lt;br /&gt;{&lt;br /&gt;    HttpClient httpClient = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClient();&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; response = await httpClient.GetStringAsync(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://www.microsoft.com/en-us/default.aspx&amp;quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (Exception) {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Handle exception.&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;For more info about &lt;b&gt;WinJS.xhr&lt;/b&gt;, see&lt;u&gt; &lt;/u&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh761502.aspx" target="_blank"&gt;Connecting to web services (Windows Store apps using JavaScript and HTML)&lt;/a&gt;. For more information about &lt;b&gt;HttpClient&lt;/b&gt;, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh781239.aspx" target="_blank"&gt;Quickstart: Connecting using HttpClient (Windows Store apps using C#/VB/C++ and XAML)&lt;/a&gt; and the &lt;a href="http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664" target="_blank"&gt;HttpClient sample&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another common networking scenario is downloading or uploading files where the file transfer may take some time. An example would be a camera or photo gallery app that needs to upload or download photos or photo albums from a web service. These transfers can take a lot of time, so it doesn't make sense to have the user wait for the transfer to finish. The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.backgroundtransfer.aspx" target="_blank"&gt;Windows.Networking.BackgroundTransfer&lt;/a&gt; API provides the ability to download or upload files even when your app is no longer running. The app starts the transfer when it’s running in the foreground and has focus, and Windows 8 then continues the transfer in the background even if the app is no longer running.&lt;/p&gt;

&lt;p&gt;Another more specialized scenario is accessing syndicated content. The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.syndication.aspx" target="_blank"&gt;Windows.Web.Syndication&lt;/a&gt; API can retrieve feeds in the RSS or Atom formats. In addition, the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.atompub.aspx" target="_blank"&gt;Windows.Web.AtomPub&lt;/a&gt; API allows an app to publish data in various AtomPub formats.&lt;/p&gt;

&lt;p&gt;For scenarios for which a specific, higher-level networking protocol is not available through an API, the Windows Runtime also supports TCP and UDP sockets (along with multicast). The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.aspx" target="_blank"&gt;Windows.Networking.Sockets&lt;/a&gt; API provides a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.streamsocket.aspx" target="_blank"&gt;StreamSocket&lt;/a&gt; (TCP) and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocket.aspx" target="_blank"&gt;DatagramSocket&lt;/a&gt; (UDP) to let you to implement other, higher-layer protocols.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Note: &lt;/b&gt;Windows 8 introduces a new type of socket called a &lt;i&gt;WebSocket&lt;/i&gt;. For more information about WebSockets and when to use them, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh761442.aspx" target="_blank"&gt;Connecting with WebSockets&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The following table provides a more complete list of supported networking features, with links to additional information.&lt;/p&gt;

&lt;div align="center"&gt;&amp;#160; &lt;table class="b8table" cellspacing="0" cellpadding="3" align="center" border="0"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;p align="center"&gt;&lt;b&gt;APIs&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="center"&gt;&lt;b&gt;Functionality&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="center"&gt;&lt;b&gt;Examples&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;ul&gt;
            &lt;li&gt;
              &lt;div align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.syndication.aspx" target="_blank"&gt;Windows.Web.Syndication&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.atompub.aspx" target="_blank"&gt;Windows.Web.AtomPub&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Retrieving feeds in the RSS or Atom formats across multiple versions. These APIs make it easy to implement support for newer formats such as OData. The Windows Runtime also supports the Atom Publishing Protocol, enabling the publication of Atom collections. 
            &lt;br /&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452973.aspx/" target="_blank"&gt;Accessing and managing syndicated content&lt;/a&gt;.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Syndication-sample-07ef6b0d" target="_blank"&gt;Syndication sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/AtomPub-sample-c1fcdc8e" target="_blank"&gt;AtomPub sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;RSS Readers&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.backgroundtransfer.aspx" target="_blank"&gt;Windows.Networking.BackgroundTransfer&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Uninterrupted, cost-aware, and resumeable downloading and uploading of content, even when the calling app is not in the foreground. This API supports content transfer using the HTTP, HTTPS, and FTP protocols. 
            &lt;br /&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452979.aspx" target="_blank"&gt;Transferring data in the background&lt;/a&gt;.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Background-Transfer-Sample-d7833f61" target="_blank"&gt;Background Transfer sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;SkyDrive&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Xbox Video&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453379.aspx" target="_blank"&gt;XMLHTTPRequest&lt;/a&gt;&lt;/b&gt;&lt;b&gt; (JavaScript&lt;/b&gt;&lt;b&gt;) &lt;/b&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br229787.aspx" target="_blank"&gt;WinJS.xhr&lt;/a&gt;&lt;/b&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;(JavaScript)&lt;/b&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx" target="_blank"&gt;HttpClient&lt;/a&gt;&lt;/b&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;(C#)&lt;/b&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh831163.aspx"&gt;XML HTTP Request 2&lt;/a&gt;&lt;/b&gt;&lt;b&gt; (IXHR2)&lt;/b&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;(C++)&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Interacting with REST-based web services and other HTTP-based protocols. 
            &lt;br /&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh761502.aspx" target="_blank"&gt;Connecting to web services&lt;/a&gt;.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/XHR-handling-navigation-50d03a7a" target="_blank"&gt;XHR, handling navigation errors, and URL schemes sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664" target="_blank"&gt;HttpClient sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Bing Maps&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.proximity.aspx" target="_blank"&gt;Windows.Networking.Proximity&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Detecting close proximity between two devices, after which apps can trigger network communication between them using socket APIs. 
            &lt;br /&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465229.aspx" target="_blank"&gt;Supporting proximity and tapping&lt;/a&gt;.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Proximity-Sample-88129731" target="_blank"&gt;Proximity sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Games&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Collaborative apps&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/library/windows/apps/BR207928" target="_blank"&gt;Windows.Storage.Pickers&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Communicating with remote file shares. 
            &lt;br /&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464959.aspx" target="_blank"&gt;Accessing data and files&lt;/a&gt;.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/File-picker-sample-9f294cba" target="_blank"&gt;File picker sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Xbox Music&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Photos&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.aspx" target="_blank"&gt;Windows.Networking.Sockets&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Connecting to a service that uses a protocol not supported by APIs already mentioned, like SMTP, MAPI, or telnet, or connecting to another device on the same local network. Also used for apps that require socket-like semantics (asynchronous, bidirectional) to connect through the web (including HTTP proxies) to a new service. 
            &lt;br /&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452977.aspx" target="_blank"&gt;Connecting with sockets&lt;/a&gt;.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/StreamSocket-Sample-8c573931" target="_blank"&gt;StreamSocket sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/DatagramSocket-sample-76a7d82b" target="_blank"&gt;DatagramSocket sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Connecting-with-WebSockets-643b10ab" target="_blank"&gt;Connecting with WebSockets sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/site/search?query=controlchanneltrigger&amp;amp;f%5B0%5D.Value=controlchanneltrigger&amp;amp;f%5B0%5D.Type=SearchText&amp;amp;ac=3" target="_blank"&gt;ControlChannelTrigger samples&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Lync, collaborative whiteboard, or stock pickers&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="217"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/library/windows/apps/BR241587" target="_blank"&gt;Windows.Storage.ApplicationData&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="221"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Windows 8 automatically transitions certain application data between user devices. Roaming application data benefits apps where the user utilizes more than one device, such as a PC at work and a tablet at home, and installs the app on multiple devices. 
            &lt;br /&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465094.aspx" target="_blank"&gt;Guidelines for roaming application data&lt;/a&gt;.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="145"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;&lt;a href="http://go.microsoft.com/fwlink/p/?linkid=231478" target="_blank"&gt;Application data sample&lt;/a&gt;&lt;/div&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;

&lt;h2&gt;Choose the right network capabilities&lt;/h2&gt;

&lt;p&gt;Network isolation is part of the app security model used by Windows 8. Windows actively discovers network boundaries and enforces network access restrictions for network isolation. When you deploy them properly, these capabilities help protect your users and apps from malicious attacks.&lt;/p&gt;

&lt;p&gt;Apps must declare network isolation capabilities in order to define the scope of network access. Without declaring these capabilities, your app will not have access to network resources. See &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/Hh770532.aspx" target="_blank"&gt;How to set network capabilities&lt;/a&gt; to learn more about how Windows enforces network isolation for apps. &lt;/p&gt;

&lt;p&gt;Note that you can’t use networking as an interprocess communication mechanism between a Windows Store app and a desktop app on the same device. So you can’t use IP loopback addresses in a Windows Store app. There are limited exceptions for development purposes that allow use of IP loopback addresses when operating under the Visual Studio debugger. For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/Hh780593.aspx" target="_blank"&gt;How to enable loopback and troubleshoot network isolation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Network access requests come in two categories: &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;b&gt;Outbound, client-initiated requests&lt;/b&gt;: Your app acts as the client and initiates network access by sending an initial network request to a remote computer, usually a server. The app sends one or more requests to the server and the server sends back a single response or several responses. For example, all traffic from a web client app to a web server would be in this category.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Inbound, unsolicited requests&lt;/b&gt;: Your app acts as a network server and listens for inbound network requests from a remote computer. The remote computer initiates network access by sending an initial request to your app, which acts as a server. The remote computer sends one or more requests to your app, which sends back one or more responses to the remote computer. For example, an app that functions as a media server would be in this category.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Follow the principle of least privilege and add only capabilities your app needs. Your app might need only outbound, client-initiated requests, or it may also need to receive inbound, unsolicited requests. Some apps may also need access to user credentials and certificates when authenticating over a network. &lt;/p&gt;

&lt;p&gt;The following table details the network isolation capabilities and other related capabilities often needed for connected apps. The first three are the primary network-isolation capabilities that connected apps use. In fact, your connected app must enable at least one of those first three capabilities. The other entries in the table are additional capabilities often needed by some connected apps.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div align="center"&gt;
  &lt;table class="b8table" cellspacing="0" cellpadding="3" width="612" align="center" border="0"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="146"&gt;
          &lt;p&gt;&lt;b&gt;Network capability&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="273"&gt;
          &lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="191"&gt;
          &lt;p&gt;&lt;b&gt;Example apps&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="146"&gt;
          &lt;p align="left"&gt;Internet (Client)&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="273"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Provides outbound access to the Internet and networks in public places like airports and coffee shops. Most apps that require Internet access should declare this capability.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="191"&gt;
          &lt;p align="left"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;

          &lt;ul&gt;
            &lt;li&gt;
              &lt;div align="left"&gt;RSS readers&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Social networks&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Games&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="146"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Internet (Client &amp;amp; Server)&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="273"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Provides both inbound and outbound access to the Internet and networks in public places like airports and coffee shops. Inbound access to critical ports are always blocked. This capability is a superset of the Internet (Client) capability; there is no need to declare both.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="191"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;P2P apps&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Multiplayer games that discover players by using multicast&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="146"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Private Networks (Client &amp;amp; Server)&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="273"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Provides inbound and outbound network access at private locations trusted by the user. These are usually home or work networks. Inbound access to critical ports are always blocked.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="191"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Apps that access network attached storage (NAS) content&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Line-of-business apps&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Multiplayer games that discover players by using multicast on a private (home or work) network&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="146"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Proximity&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="273"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Required for near-field proximity communication with devices. Allows apps to access the network to connect to a device in close proximity, with user consent to send or accept an invitation.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="191"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Multiplayer games with people in close proximity&lt;i&gt;&lt;/i&gt;&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="146"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Enterprise Authentication&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="273"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Provides the capability to connect to enterprise intranet resources that require domain credentials.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="191"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Line-of-business apps&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="146"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Shared User Certificates&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="273"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Provides the capability to access software and hardware certificates, such as smart card certificates, for validating a user's identity. When related APIs are invoked at run time, the user must take action (such as inserting a card or selecting a certificate). &lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="191"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Virtual private network apps&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Line-of-business apps&lt;/div&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;Use this checklist to make sure network isolation is configured in your app:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Determine the direction of network access that your app needs; outbound client-initiated requests, inbound unsolicited requests, or both.&lt;/li&gt;

  &lt;li&gt;Determine the type of network resources that your app will communicate with: trusted resources on a home or work network, resources on the Internet, or both. &lt;/li&gt;

  &lt;li&gt;Configure the minimum required network isolation capabilities in the app manifest. You can do this using the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br230259.aspx" target="_blank"&gt;App Manifest Designer&lt;/a&gt; in Microsoft Visual Studio 2012, or &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211477.aspx" target="_blank"&gt;add them manually&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;Deploy and run your app to test it using the network isolation tools provided for troubleshooting. For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/Hh780593.aspx" target="_blank"&gt;How to enable loopback and troubleshoot network isolation&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following screen shot shows how to enable network capabilities using the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br230259.aspx" target="_blank"&gt;App Manifest Designer&lt;/a&gt; in Microsoft Visual Studio 2012.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7268.app_2D00_manifest_2D00_design_5F00_47107BBF.png"&gt;&lt;img title="Select network capabilities in your app’s package.appxmanifest in Visual Studio 2012" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Select network capabilities in your app’s package.appxmanifest in Visual Studio 2012" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7752.app_2D00_manifest_2D00_design_5F00_thumb_5F00_5EC7B325.png" width="600" height="318" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="center"&gt;&lt;em&gt;Select network capabilities in your app’s package.appxmanifest in Visual Studio 2012&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;Adapt app behavior for metered networks&lt;/h2&gt;

&lt;p&gt;Think about the last time you were approaching your monthly data cap or perhaps travelled abroad. In these situations I typically ended up using my device and apps cautiously to prevent any unnecessary network charges. &lt;/p&gt;

&lt;p&gt;Windows 8 addresses this user problem by allowing apps to monitor available network resources and behave accordingly when on metered networks. To promote user confidence in your apps, you can make it able to tell when a connection may incur costs and then adapt its behavior to avoid or reduce charges.&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.aspx" target="_blank"&gt;Windows.Networking.Connectivity&lt;/a&gt; API provides info about the type and cost of a network connection. This allows your app to determine when it makes sense to use network resources normally, use them conservatively, or ask the user. &lt;/p&gt;

&lt;p&gt;A &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectionprofile.aspx" target="_blank"&gt;ConnectionProfile&lt;/a&gt; represents a network connection. Your app can use the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.aspx" target="_blank"&gt;ConnectionCost&lt;/a&gt; of a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectionprofile.aspx" target="_blank"&gt;ConnectionProfile&lt;/a&gt; to determine whether to adapt its behavior. The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.networkcosttype.aspx" target="_blank"&gt;NetworkCostType&lt;/a&gt; property indicates the type of a network connection. There are four possible values:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Unrestricted&lt;/b&gt;—Use of this network connection is unlimited. It has no usage charges or capacity constraints.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Fixed&lt;/b&gt;—Use of this network connection is unrestricted up to a specific limit.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Variable&lt;/b&gt;—Use of this network connection is metered on a per-byte basis.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Unknown&lt;/b&gt;—Cost information is not available for this network connection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Several other Boolean properties for the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.aspx" target="_blank"&gt;ConnectionCost&lt;/a&gt; provide still more info. &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.roaming.aspx" target="_blank"&gt;Roaming&lt;/a&gt;—The connection is to a network outside of the home provider.&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.approachingdatalimit.aspx" target="_blank"&gt;ApproachingDataLimit&lt;/a&gt;—The connection is approaching the usage allowance specified by the data plan.&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.overdatalimit.aspx" target="_blank"&gt;OverDataLimit&lt;/a&gt;—The connection has exceeded the usage allowance specified by the data plan.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have your app respond to the conditions indicated by these properties. Whenever a connection is &lt;b&gt;Roaming&lt;/b&gt;, the data costs associated with network usage could be high. When the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.networkcosttype.aspx" target="_blank"&gt;NetworkCostType&lt;/a&gt; is &lt;b&gt;Variable&lt;/b&gt;, the network is a metered network, where the user pays for the amount of data sent or received on the network. When the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.networkcosttype.aspx" target="_blank"&gt;NetworkCostType&lt;/a&gt; is &lt;b&gt;Fixed&lt;/b&gt;, there’s cause for concern if the user is already over the data limit or approaching it. &lt;/p&gt;

&lt;p&gt;By using this information, an app can follow these guidelines to decide how best to use network resources.&lt;/p&gt;

&lt;div align="center"&gt;
  &lt;table class="b8table" cellspacing="0" cellpadding="3" align="center" border="0"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="97"&gt;
          &lt;p&gt;&lt;b&gt;Behavior&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="150"&gt;
          &lt;p&gt;&lt;b&gt;Connection cost&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="168"&gt;
          &lt;p&gt;&lt;b&gt;App guidelines&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="175"&gt;
          &lt;p&gt;&lt;b&gt;Examples&lt;/b&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="97"&gt;
          &lt;p align="left"&gt;Normal&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="150"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.networkcosttype.aspx" target="_blank"&gt;NetworkCostType&lt;/a&gt; is &lt;b&gt;Unrestricted&lt;/b&gt; or &lt;b&gt;Unknown&lt;/b&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.aspx" target="_blank"&gt;ConnectionCost&lt;/a&gt; is not &lt;b&gt;Roaming&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="168"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;App does not implement restrictions. App treats the connection as &lt;b&gt;Unlimited&lt;/b&gt; in cost, and unrestricted by usage charges and capacity constraints.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="175"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Media player app can play an entire HD movie.&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;App can download large file without any restrictions or prompts.&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;
      &lt;/tr&gt;

      &lt;p align="left"&gt;&lt;/p&gt;

      &lt;tr&gt;
        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="97"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Conservative&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="150"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.networkcosttype.aspx" target="_blank"&gt;NetworkCostType&lt;/a&gt; is &lt;b&gt;Fixed&lt;/b&gt; or &lt;b&gt;Variable&lt;/b&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.aspx" target="_blank"&gt;ConnectionCost&lt;/a&gt; is not &lt;b&gt;Roaming&lt;/b&gt; or &lt;b&gt;OverDataLimit&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="168"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;App implements restrictions for optimizing network usage to handle operations on metered networks.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="175"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;Media player app can play movies in lower resolutions.&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;App can delay non-critical downloads.&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;
          &lt;/ul&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;
      &lt;/tr&gt;

      &lt;p align="left"&gt;&lt;/p&gt;

      &lt;tr&gt;
        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="97"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;Opt-In&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="150"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.aspx" target="_blank"&gt;ConnectionCost&lt;/a&gt; is &lt;b&gt;Roaming&lt;/b&gt; or &lt;b&gt;OverDataLimit&lt;/b&gt;&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="168"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;p align="left"&gt;App handles exceptional cases where the network access cost is substantially higher than plan cost.&lt;/p&gt;

          &lt;p align="left"&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;p align="left"&gt;&lt;/p&gt;

        &lt;td valign="top" width="175"&gt;
          &lt;p align="left"&gt;&lt;/p&gt;

          &lt;ul&gt;
            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;App prompts user to access the network.&lt;/div&gt;
            &lt;/li&gt;

            &lt;p align="left"&gt;&lt;/p&gt;

            &lt;li&gt;
              &lt;div align="left"&gt;App suspends all background data network activities.&lt;i&gt;&lt;/i&gt;&lt;/div&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;This code example checks the connection cost and returns suggestions for appropriate app behavior. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; CostGuidance = { Normal: 0, Conservative: 1, OptIn: 2 };&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// GetCostGuidance returns an object with a Cost (with value of CostGuidance), &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// CostName (a string) and Reason, which says why the cost is what it is.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; GetCostGuidance() &lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; connectionCost = Windows.Networking.Connectivity.NetworkInformation.getInternetConnectionProfile().getConnectionCost();&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; networkCostConstants = Windows.Networking.Connectivity.NetworkCostType;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; Retval = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Object();&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (connectionCost.roaming || connectionCost.overDataLimit)&lt;br /&gt;    {&lt;br /&gt;        Retval.Cost = CostGuidance.OptIn;&lt;br /&gt;        Retval.CostName = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;OptIn&amp;quot;&lt;/span&gt;;&lt;br /&gt;        Retval.Reason = connectionCost.roaming&lt;br /&gt;            ? &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection is roaming; using the connection may result in additional charge.&amp;quot;&lt;/span&gt;&lt;br /&gt;            : &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection has exceeded the usage cap limit.&amp;quot;&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (connectionCost.networkCostType == networkCostConstants.&lt;span style="color: rgb(0, 0, 255);"&gt;fixed&lt;/span&gt;&lt;br /&gt;        || connectionCost.networkCostType == networkCostConstants.variable)&lt;br /&gt;    {&lt;br /&gt;        Retval.Cost = CostGuidance.conservative;&lt;br /&gt;        Retval.CostName = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Conservative&amp;quot;&lt;/span&gt;;&lt;br /&gt;        Retval.Reason = connectionCost.networkCostType == NetworkCostType.&lt;span style="color: rgb(0, 0, 255);"&gt;fixed&lt;/span&gt;&lt;br /&gt;            ? &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection has limited allowed usage.&amp;quot;&lt;/span&gt;&lt;br /&gt;            : &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection is charged based on usage. &amp;quot;&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        Retval.Cost = CostGuidance.Normal;&lt;br /&gt;        Retval.CostName = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Normal&amp;quot;&lt;/span&gt;;&lt;br /&gt;        Retval.Reason = connectionCost.networkCostType == networkCostConstants.unknown&lt;br /&gt;            ? &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection is unknown.&amp;quot;&lt;/span&gt;&lt;br /&gt;            : &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection cost is unrestricted.&amp;quot;&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Retval;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;enum&lt;/span&gt; NetworkCost { Normal, Conservative, OptIn };&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; CostGuidance&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; CostGuidance()&lt;br /&gt;    {&lt;br /&gt;        var connectionCost = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost();&lt;br /&gt;        Init(connectionCost);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; NetworkCost Cost { get; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; set; }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; String Reason { get; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; set; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Init(ConnectionCost connectionCost)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (connectionCost == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (connectionCost.Roaming || connectionCost.OverDataLimit)&lt;br /&gt;        {&lt;br /&gt;            Cost = NetworkCost.OptIn;&lt;br /&gt;            Reason = connectionCost.Roaming&lt;br /&gt;                ? &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection is roaming; using the connection may result in additional charge.&amp;quot;&lt;/span&gt;&lt;br /&gt;                : &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection has exceeded the usage cap limit.&amp;quot;&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (connectionCost.NetworkCostType == NetworkCostType.Fixed&lt;br /&gt;            || connectionCost.NetworkCostType == NetworkCostType.Variable)&lt;br /&gt;        {&lt;br /&gt;            Cost = NetworkCost.Conservative;&lt;br /&gt;            Reason = connectionCost.NetworkCostType == NetworkCostType.Fixed&lt;br /&gt;                ? &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection has limited allowed usage.&amp;quot;&lt;/span&gt;&lt;br /&gt;                : &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection is charged based on usage. &amp;quot;&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            Cost = NetworkCost.Normal;&lt;br /&gt;            Reason = connectionCost.NetworkCostType == NetworkCostType.Unknown&lt;br /&gt;                ? &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection is unknown.&amp;quot;&lt;/span&gt;&lt;br /&gt;                : &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Connection cost is unrestricted.&amp;quot;&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Network-Information-Sample-63aaa201" target="_blank"&gt;network information sample&lt;/a&gt; to learn more about adapting app behavior for metered networks.&lt;/p&gt;

&lt;p&gt;Users can also run Task Manager to see the amount of network data that each app is consuming. This screen shot shows an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/5618.task_2D00_manager_5F00_6C99F920.png"&gt;&lt;img title="App History tab in Task Manager allows users to see CPU and network consumption by apps" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="App History tab in Task Manager allows users to see CPU and network consumption by apps" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3554.task_2D00_manager_5F00_thumb_5F00_4C7EEC63.png" width="600" height="545" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="center"&gt;&lt;em&gt;App History tab in Task Manager allows users to see CPU and network consumption by apps&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;React to network status changes&lt;/h2&gt;

&lt;p&gt;In any mobile device scenario, networks can come and go. A mobile 3G or 4G broadband network could go out of range within a user’s home or garage while Wi-Fi is still available. Similarly, Wi-Fi may go out of range when a user leaves home. There may also be times when no network is available. Given the proliferation of Wi-Fi and mobile broadband networks, such network changes occur frequently. &lt;/p&gt;

&lt;p&gt;A &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkinformation.networkstatuschanged" target="_blank"&gt;NetworkStatusChanged&lt;/a&gt; event indicates that the &lt;i&gt;available cost&lt;/i&gt; or &lt;i&gt;connectivity options&lt;/i&gt; may have changed. To react to network status changes and provide a seamless customer experience when a change occurs, have your connected apps follow these scenario guidelines.&lt;/p&gt;

&lt;h3&gt;Connection loss due to error&lt;/h3&gt;

&lt;p&gt;In most cases, connections can be reestablished by simply retrying the network operation. If this fails, then wait for a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkinformation.networkstatuschanged" target="_blank"&gt;NetworkStatusChanged&lt;/a&gt; event. We recommend that apps use an increasing backoff interval between retries, starting with a value of 50 milliseconds and increasing this backoff interval exponentially if connections continue to fail.&lt;/p&gt;

&lt;h3&gt;Loss of network&lt;/h3&gt;

&lt;p&gt;Inform the user that the connection has been lost, then register and wait for a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkinformation.networkstatuschanged" target="_blank"&gt;NetworkStatusChanged&lt;/a&gt; event.&lt;/p&gt;

&lt;h3&gt;New network availability&lt;/h3&gt;

&lt;p&gt;There may be cases where the device is connected to multiple networks. For example, a user may be connected to mobile broadband and chatting with friends using the Windows 8 Messaging app before arriving at home and connecting to the unrestricted network there as well. The default policy in Windows 8 is to prefer an unrestricted network over a metered network, and a faster network over a slower network. However, existing connections established by an app do not automatically switch over to a new network. The app must get involved because only the app can make the best decision whether or not to switch to the new network. &lt;/p&gt;

&lt;p&gt;For example, if a video stream is close to completion, it may not make sense to switch to the new network. However, if the current network is dropping packets, is too slow, or the stream will take additional time to complete, switching to the new network may be best.&lt;/p&gt;

&lt;p&gt;If you determine that switching networks is plausible for your app scenario, follow these guidelines when you detect a new network:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Check the network costs of the existing and new network. If it makes sense to switch to the new network, try making a new network connection and retry the network operation based on the guidelines just mentioned. Windows automatically selects the unrestricted network over the metered network, and the faster network over the slower one if available.&lt;/li&gt;

  &lt;li&gt;If the new network connection succeeds, use the new network connection in your app and cancel the original network operation on the previous network if the connection already exists.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Change in network cost&lt;/h3&gt;

&lt;p&gt;A change in network cost can occur when the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.networkcosttype.aspx" target="_blank"&gt;NetworkCostType&lt;/a&gt; is &lt;b&gt;Fixed&lt;/b&gt; and usage is approaching the data limit or goes over the data limit. A change in network cost can also result if the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.networkcosttype.aspx" target="_blank"&gt;NetworkCostType&lt;/a&gt; becomes &lt;b&gt;Variable&lt;/b&gt;, or if &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectioncost.roaming.aspx" target="_blank"&gt;Roaming&lt;/a&gt; changes to true. In these cases, adapt app behavior based on the guidelines in the preceding tip.&lt;/p&gt;

&lt;p&gt;These code examples use the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkinformation.networkstatuschanged" target="_blank"&gt;NetworkStatusChanged&lt;/a&gt; event to provide a seamless app experience for various network status changes. Both examples use a global Boolean variable called &lt;i&gt;registeredNetworkStatusNotification,&lt;/i&gt; initially set to &lt;b&gt;false&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Register for NetworkStatusChanged notifications, and display new &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Internet ConnectionProfile info upon network status change.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; registerForNetworkStatusChange() {&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Register for network status change notifications.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!registeredNetworkStatusNotification) {&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; networkInfo.addEventListener(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;networkstatuschanged&amp;quot;&lt;/span&gt;, onNetworkStatusChange);&lt;br /&gt;            registeredNetworkStatusNotification = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (e) {&lt;br /&gt;        print(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;An unexpected exception occurred: &amp;quot;&lt;/span&gt; + e.name + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;: &amp;quot;&lt;/span&gt; + e.message);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Event handler for NetworkStatusChanged event&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; onNetworkStatusChange(sender) {&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Get the ConnectionProfile that is currently used to connect &lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// to the Internet.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; internetProfile = networkInfo.getInternetConnectionProfile();&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (internetProfile === &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;) {&lt;br /&gt;            print(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Not connected to Internet\n\r&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; {&lt;br /&gt;            internetProfileInfo += getConnectionProfileInfo(internetProfile) + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;\n\r&amp;quot;&lt;/span&gt;;&lt;br /&gt;            print(internetProfileInfo);&lt;br /&gt;        }&lt;br /&gt;        internetProfileInfo = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (e) {&lt;br /&gt;        print(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;An unexpected exception occurred: &amp;quot;&lt;/span&gt; + e.name + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;: &amp;quot;&lt;/span&gt; + e.message);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Register for NetworkStatusChanged notifications, and display new &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Internet ConnectionProfile info upon network status change.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; NetworkStatusChange()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Register for network status change notifications.&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        var networkStatusCallback = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; NetworkStatusChangedEventHandler(OnNetworkStatusChange);&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!registeredNetworkStatusNotification)&lt;br /&gt;        {&lt;br /&gt;            NetworkInformation.NetworkStatusChanged += networkStatusCallback;&lt;br /&gt;            registeredNetworkStatusNotification = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;    {&lt;br /&gt;        rootPage.NotifyUser(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Unexpected exception occurred: &amp;quot;&lt;/span&gt; + ex.ToString(), NotifyType.ErrorMessage);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Event handler for NetworkStatusChanged event&lt;/span&gt;&lt;br /&gt;async &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OnNetworkStatusChange(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Get the ConnectionProfile that is currently used to connect &lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// to the Internet                &lt;/span&gt;&lt;br /&gt;        ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (InternetConnectionProfile == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br /&gt;        {&lt;br /&gt;            await _cd.RunAsync(CoreDispatcherPriority.Normal, () =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                rootPage.NotifyUser(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Not connected to Internet\n&amp;quot;&lt;/span&gt;, NotifyType.StatusMessage);&lt;br /&gt;            });&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);&lt;br /&gt;            await _cd.RunAsync(CoreDispatcherPriority.Normal, () =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                rootPage.NotifyUser(connectionProfileInfo, NotifyType.StatusMessage);&lt;br /&gt;            });&lt;br /&gt;        }&lt;br /&gt;        internetProfileInfo = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;    {&lt;br /&gt;        rootPage.NotifyUser(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Unexpected exception occurred: &amp;quot;&lt;/span&gt; + ex.ToString(), NotifyType.ErrorMessage);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;To learn more about the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkinformation.networkstatuschanged" target="_blank"&gt;NetworkStatusChanged&lt;/a&gt; event, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh700376.aspx" target="_blank"&gt;Quickstart: Managing connection events and changes in availability&lt;/a&gt; and the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Network-Information-Sample-63aaa201" target="_blank"&gt;Network information sample&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Cache content for fluidity&lt;/h2&gt;

&lt;p&gt;Caching content to disk lets your app behave fast and fluidly. For example, an RSS feed reader app can immediately display feeds that were cached to disk from a previous session. As soon as the latest feeds are available, the app updates its content. Caching ensures that the user has content to read immediately upon launch while the app gets new content.&lt;/p&gt;

&lt;p&gt;Windows 8 provides the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.aspx" target="_blank"&gt;ApplicationData&lt;/a&gt;&lt;b&gt;&lt;/b&gt; class in the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.aspx" target="_blank"&gt;Windows.Storage&lt;/a&gt;&lt;b&gt;&lt;/b&gt; namespace. This class provides access to the app data store. This data store consists of files and settings that are local to the device, roam across multiple devices, or are temporary.&lt;/p&gt;

&lt;p&gt;Files are ideal for storing large data sets, databases, or data that is in a common file format. Files can exist in the Roaming, Local, or Temporary folders. Here’s what that means:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Roaming files are synchronized across multiple machines and devices where users have signed in with connected accounts. Roaming of files is not instant; the system weighs several factors to determine when to send the data. Keep the use of roaming data below the quota (available via the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.roamingstoragequota.aspx" target="_blank"&gt;RoamingStorageQuota&lt;/a&gt;&lt;b&gt;&lt;/b&gt; property); if the quota is exceeded, roaming of data will be suspended. Files cannot be roamed while an app is writing to them, so be sure to close your app’s file objects when they are no longer needed. &lt;/li&gt;

  &lt;li&gt;Local files are not synchronized across machines. They remain on the machine on which they were originally written. &lt;/li&gt;

  &lt;li&gt;Temporary files are subject to deletion when not in use. The system considers factors such as available disk capacity and the age of a file in determining when or whether to delete a temporary file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These code examples cache content to disk. Caching the server response allows your app to immediately display content to the user after a termination and relaunch. For brevity, these examples don’t show how to write settings to the app data store or how to respond to roaming events. The &lt;a href="http://code.msdn.microsoft.com/windowsapps/ApplicationData-sample-fb043eb2" target="_blank"&gt;Application data sample&lt;/a&gt; covers those details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; roamingFolder = Windows.Storage.ApplicationData.current.roamingFolder;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; filename = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;serverResponse.txt&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; cacheResponse(strResponse) {&lt;br /&gt;    roamingFolder.createFileAsync(filename, Windows.Storage.CreationCollisionOption.replaceExisting)&lt;br /&gt;        .done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (file) {&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Windows.Storage.FileIO.writeTextAsync(file, strResponse);&lt;br /&gt;        });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; getCachedResponse() {&lt;br /&gt;    roamingFolder.getFileAsync(filename)&lt;br /&gt;        .then(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (file) {&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Windows.Storage.FileIO.readTextAsync(file);&lt;br /&gt;        }).done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (response) {&lt;br /&gt;            print(response);&lt;br /&gt;        }, &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; () {&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// getFileAsync or readTextAsync failed. &lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// No cached response.&lt;/span&gt;&lt;br /&gt;        });&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;MainPage rootPage = MainPage.Current;&lt;br /&gt;StorageFolder roamingFolder = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;const&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; filename = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;serverResponse.txt&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;async &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; cacheResponse(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; strResponse)&lt;br /&gt;{&lt;br /&gt;    StorageFile file = await roamingFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);&lt;br /&gt;    await FileIO.WriteTextAsync(file, strResponse);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;async &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; getCachedResponse()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        StorageFile file = await roamingFolder.GetFileAsync(filename);&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; response = await FileIO.ReadTextAsync(file);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (Exception)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// getFileAsync or readTextAsync failed.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// No cached response.&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;For more info about the app data store, see the &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/07/17/roaming-your-app-data.aspx" target="_blank"&gt;roaming your app data&lt;/a&gt; post and try out the &lt;a href="http://code.msdn.microsoft.com/windowsapps/ApplicationData-sample-fb043eb2" target="_blank"&gt;Application data sample&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Wrapping it up&lt;/h2&gt;

&lt;p&gt;When planning your Windows Store apps, use the guidelines in this post to provide a great, hassle-free, connected experience. These tips can make your development process easier, while maintaining fluidity and boosting user confidence in your apps.&lt;/p&gt;

&lt;p&gt;- Suhail Khalid, Program Manager II, Windows&lt;/p&gt;

&lt;p&gt;Contributions by: Steven Baker and Peter Smith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10409510" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+Store+apps/">Windows Store apps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/connected+apps/">connected apps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/XMLHTTPRequest/">XMLHTTPRequest</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/IXHR2/">IXHR2</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/XML+HTTP+Request+2/">XML HTTP Request 2</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/WinJS-xhr/">WinJS.xhr</category></item><item><title>Register now for //build/ 2013!</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/02/register-now-for-build-2013.aspx</link><pubDate>Tue, 02 Apr 2013 15:23:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10406954</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10406954</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/02/register-now-for-build-2013.aspx#comments</comments><description>&lt;p&gt;Last week Steve Guggenheimer &lt;a href="http://blogs.technet.com/b/microsoft_blog/archive/2013/03/26/announcing-build-2013.aspx" target="_blank"&gt;announced&lt;/a&gt; //build/ 2013. The conference is taking place June 26-28, 2013 at the Moscone Center in San Francisco. //build/ is a great opportunity to learn more about developing Windows Store apps. The conference will include great presentations, demos, info sessions, etc. for you. Many of us from the engineering team are traveling down to San Francisco to give these demos and answer your questions. There’s no better place to get the latest and greatest info on Windows Store app development. &lt;/p&gt;  &lt;p&gt;Registration begins today, Tuesday April 2&lt;sup&gt;nd&lt;/sup&gt;. You can see all the details about the conference and register at &lt;a href="http://www.buildwindows.com" target="_blank"&gt;www.buildwindows.com&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;We hope to see you there!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10406954" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/build/">build</category></item><item><title>Windows Store app support in jQuery version 2.0</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/01/windows-store-app-support-in-jquery-version-2-0.aspx</link><pubDate>Mon, 01 Apr 2013 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10406723</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10406723</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/04/01/windows-store-app-support-in-jquery-version-2-0.aspx#comments</comments><description>&lt;p&gt;If you’ve already done some web development, it’s likely you’ve used the open source JavaScript framework jQuery. And if you’ve tried building Windows Store apps using jQuery, you might have run into errors related to JavaScript runtime or dynamic content. With the upcoming release of v2.0, the jQuery team has addressed these concerns. The jQuery v2 beta now supports development in HTML5/JS for Windows Store apps. As a web developer, you can use your existing skills and assets to build awesome apps for Windows 8. You can &lt;a href="http://jquery.com/download/" target="_blank"&gt;try it with the latest jQuery 2.0 beta build now&lt;/a&gt;.&lt;i&gt; &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;“The jQuery team is excited about the new environments where jQuery 2.0 can be used. HTML and JavaScript developers want to take their jQuery knowledge with them to streamline the development process wherever they work. jQuery 2.0 gives them the ability to do that in environments such as Windows 8 Store applications.”&lt;/i&gt; - &lt;a href="https://twitter.com/davemethvin" target="_blank"&gt;Dave Methvin&lt;/a&gt;, president, jQuery Foundation&lt;i&gt;&lt;/i&gt;&lt;/p&gt;  &lt;h2&gt;Windows Store app: a different context for JavaScript code&lt;/h2&gt;  &lt;p&gt;You might be wondering why jQuery didn’t “just work” before. All Windows Store Apps, whether written in HTML/JS, C# or C++, have native access to the Windows Runtime, so a new security model was created to help your apps run securely on the new platform. Additionally, some of the APIs that are common to the web were modified to fit their new native environment in a more meaningful way. These differences can cause issues for code that was expecting to be running in a browser. Most issues are related to dynamic content – you may have gotten “HTML1701: Unable to add dynamic content…” or exceptions “0x800c001c - JavaScript runtime error: Unable to add dynamic content...”&lt;/p&gt;  &lt;p&gt;For more info about this model check out the &lt;a href="http://blogs.msdn.com/b/b8/archive/2012/05/17/delivering-reliable-and-trustworthy-metro-style-apps.aspx" target="_blank"&gt;Delivering reliable and trustworthy apps&lt;/a&gt; post. You can learn about &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx" target="_blank"&gt;differences between the context of a Windows Store application and a Web browser&lt;/a&gt; on the Windows Dev Center.&lt;/p&gt;  &lt;h2&gt;Updating jQuery to support the new model&lt;/h2&gt;  &lt;p&gt;As many of you know, &lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt; is a very popular JavaScript framework on the web because it makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across many browsers.&lt;/p&gt;  &lt;p&gt;To enable all these features of jQuery in your Windows Store apps the jQuery experts at &lt;a href="http://appendto.com/" target="_blank"&gt;appendTo&lt;/a&gt; worked with the jQuery community to update jQuery to support the new Windows 8 app model. Our own engineers from Microsoft Open Technologies provided technical support for the effort to make sure all the changes took full advantage of the platform.&lt;/p&gt;  &lt;p&gt;Adding support for Windows Store Apps in jQuery involved initial testing, porting of Unit Tests, and evaluating jQuery dependencies, such as the Sizzle selector engine, which is at the heart of jQuery. appendTo identified several areas in jQuery support logic, as well as sparse items throughout Sizzle, used to target elements in a document, that required re-authoring to work within the guidelines of the Windows Store app security model. &lt;/p&gt;  &lt;p&gt;appendTo submitted code directly to the jQuery Core project, which integrated this support, so now you get all this for free as soon as you add jQuery into your app. Additionally, you’ll want to practice some alternative patterns when using jQuery in a Windows Store app. You can find more info on these patterns on the &lt;a href="http://aka.ms/learnjQueryOnWinRT" target="_blank"&gt;net.tuts+ site&lt;/a&gt;. Check out &lt;a href="http://aka.ms/appendTojQueryOnWinRT" target="_blank"&gt;appendTo’s blog post&lt;/a&gt; for more details on the changes they made in their updates. &lt;/p&gt;  &lt;h2&gt;Let’s code!&lt;/h2&gt;  &lt;p&gt;If you’re an HTML5 and JavaScript developer, you can build Windows 8 apps using what you already know along with your existing JavaScript code and libraries. For your jQuery code, upgrade to &lt;a href="http://jquery.com/download/" target="_blank"&gt;jQuery 2.0&lt;/a&gt; beta and follow the &lt;a href="http://aka.ms/learnjQueryOnWinRT" target="_blank"&gt;new patterns&lt;/a&gt; shared by appendTo. If you don’t use jQuery, you can apply these same patterns and techniques to your own code and libraries to make them fully compatible with Windows 8.&lt;/p&gt;  &lt;p&gt;If you want to learn more new opportunities for using your web development skills with the Windows platforms, check out the &lt;a href="http://aka.ms/jQueryOnWinRT" target="_blank"&gt;MS Open Tech blog post.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;--Olivier Bloch, Senior Technical Evangelist, MS Open Tech&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10406723" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/JavaScript/">JavaScript</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+Store+apps/">Windows Store apps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/jQuery/">jQuery</category></item><item><title>Developing Windows Store games</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/03/22/developing-windows-store-games.aspx</link><pubDate>Fri, 22 Mar 2013 15:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10404314</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10404314</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/03/22/developing-windows-store-games.aspx#comments</comments><description>&lt;p&gt;Windows 8 has changed the PC landscape with innovative form factors, new chip architectures, exciting commerce models and huge opportunities. PC games have long been a staple of the way computers are enjoyed. Now, more than ever, games exemplify the value of this new landscape of devices. Thanks to the Windows Store, games are easier to acquire, play, share with friends and update safely. It’s no wonder then that games account for such a large number of downloads, generate a lot of revenue, and drive the most user engagement on the new platform. With &lt;a href="http://gdconf.com/" target="_blank"&gt;GDC&lt;/a&gt; around the corner, more game developers are eager to learn about the Windows 8 opportunity.&lt;/p&gt;  &lt;p&gt;So, how do you create a great Windows Store game? What does Windows offer to make your game more creative, innovative, profitable and easier to develop? What tools, technologies and services can you use? What’s available out there in the ecosystem? What are other discoveries &lt;a href="http://www.windowsstore.com/partner-stories" target="_blank"&gt;developers shared&lt;/a&gt; when developing for Windows 8? This post will answer questions about these topics and clarify how you too, can develop an awesome Windows Store game. &lt;/p&gt;  &lt;h2&gt;Windows 8 game design and development considerations&lt;/h2&gt;  &lt;p&gt;Windows 8 was designed and engineered specifically for the enjoyment of entertainment experiences. The Windows 8 User Experience (UX) guidelines promote full screen imagery, as well as fast and fluid interactions with no borders or extra window decorations. The design guidance recommends that apps focus on experiences that invite users to engage and provide interactions that guide them through an immersive experience. Main game controls should be easily accessible and secondary controls should be tucked away in an app bar or in a settings panel until they are needed. So, that’s great for general apps, but how do these principles affect games? After all, game developers have been providing fast and fluid, full screen, immersive experiences for a long time. Nevertheless, several basic questions arise almost right away:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;How can game mechanics scale from powerful desktop PCs to notebooks and tablets?&lt;/li&gt;    &lt;li&gt;What are the most important form factors to target?&lt;/li&gt;    &lt;li&gt;Can you enable games for touch, game controller and keyboard/mouse simultaneously?&lt;/li&gt;    &lt;li&gt;What are the most important screen sizes, aspect ratios and resolutions?&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Game developers have been using a wide range of technologies to deliver entertaining games to the PC community for a long time. The APIs used on Windows have evolved significantly over time. With Windows 8, a new development platform has been added. The &lt;a href="http://msdn.microsoft.com/en-US/library/windows/apps/br211377" target="_blank"&gt;Windows Runtime API&lt;/a&gt; aggregates the best technologies from APIs of the past and brings significant improvements in performance, security, development consistency and servicing. The Windows Store adds a new way for games to be discovered, distributed and serviced. These new APIs significantly add value for game developers targeting the new development model. You might have some questions when you start to develop a Windows Store game, for example: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;What are the best Windows Runtime APIs to use for game development?&lt;/li&gt;    &lt;li&gt;How do the development models map to the different game genres?&lt;/li&gt;    &lt;li&gt;How do I transition my code from other platforms?&lt;/li&gt;    &lt;li&gt;How do I update my code from older versions of Windows?&lt;/li&gt;    &lt;li&gt;What, if any, of my game assets might need updating?&lt;/li&gt;    &lt;li&gt;Are there resources to help me reduce development costs?&lt;/li&gt;    &lt;li&gt;Where is the DirectX SDK?&lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Gaming reimagined&lt;/h2&gt;  &lt;p&gt;Every game starts with an idea. Where that idea comes from can be very different. Sometimes it randomly pops into your head while you’re taking a walk, or while you’re in the shower. Other times, a more collaborative and iterative approach with your team may result in the idea. Once you’ve got your idea, you need to decide what type of game it is. Maybe you want a new unique game. Or perhaps you want to port your existing game. It could be a shooter, or puzzle, or racing game – no matter what type of game it is, there’s a home for it in the Windows Store. The &lt;a href="http://channel9.msdn.com/Events/Build/2012/3-111" target="_blank"&gt;Gaming Case Studies&lt;/a&gt; presented at //build/ 2012 might inspire you. If you have a Windows Store developer account you can browse the games’ subcategories to be inspired and see how different game categories are performing in different regions.&lt;/p&gt;  &lt;h2&gt;Game design guidance&lt;/h2&gt;  &lt;p&gt;Once you’ve decided what game you want to build, making design decisions on the front end can save you a lot of development time later on. The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh868271.aspx" target="_blank"&gt;Windows 8 game category design guidance&lt;/a&gt; gives you some ideas about how best to attract players and keep them engaged with tiles and notifications. There are also suggestions about what type of overall layout to use and where to place primary and secondary controls. &lt;/p&gt;  &lt;p&gt;You can find recommendations about interactions and how to incorporate touch, sensors and contracts into your game. Decisions about game mechanics and controls should be made as early as possible to scope development. That said, the Windows Runtime platform makes it more convenient than ever to support touch, pen (ink) and mouse with the same code so you don’t have to design special mechanics for different form factors. Because every Windows PC has a place to plug in a game controller, don’t miss out on the opportunity and make sure you include that control mechanism in your game as well. &lt;/p&gt;  &lt;p&gt;Plan how – and at what pace – you’ll introduce game interactions and mechanics to the player. Too slow and they may lose interest; too fast and they may get frustrated. Perhaps most important of all, decide what monetization model and commerce platform you’d like to use. The Windows Store allows you to &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/jj193599.aspx" target="_blank"&gt;choose your business model&lt;/a&gt;. It supports Free to Play, Ad-based, In-app Purchases and Downloadable Content. Windows Store games can take advantage of the built-in time-based or feature-based trials. Alternately, you can use a third-party commerce provider or roll your own. Either way, as these issues can significantly impact your game’s success, monetarily or in popularity, they are important to consider.&lt;/p&gt;  &lt;p&gt;Like all Windows Store apps, games have to support the different activation, view and suspension states. The design guidance offers some help with considerations for how and when to pause your game, how and when to suspend your game’s state, and how to handle full screen, snapped and filled view states. Decide how your game will support landscape and portrait orientations. Consider the size of hit targets and other on-screen controls when adjusting the resolution of your game’s assets to match different screen sizes (or parts of them). Also don’t forget to take screen aspect ratios, resolutions, and DPI settings into consideration. This will make sure your game’s content renders correctly on any screen size and scale factor.&lt;/p&gt;  &lt;p&gt;Finally, remember to consider a few additional things that can help increase your game’s accessibility and socialization capabilities. A high contrast mode and extra audio queues could help increase visibility or playability and therefore encourage adoption among players in less than ideal lighting conditions or with visual impairments. Additionally, leveraging the platform’s built-in capabilities for &lt;a href="http://msdn.microsoft.com/en-US/library/windows/apps/xaml/Hh465283"&gt;online identity&lt;/a&gt; (authentication), data &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700362.aspx"&gt;roaming&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh871373(v=win.10).aspx"&gt;sharing&lt;/a&gt; to other apps can lead to increased engagement through social activity such as comparing game results and playing games across different PCs.&lt;/p&gt;  &lt;h2&gt;Game development guidance&lt;/h2&gt;  &lt;p&gt;DirectX is considered to be at the heart of the Windows game development platform. However, many other components were developed and transitioned in to the Windows 8 SDK to provide all the required capabilities the platform needs to support the diverse Windows gaming ecosystem. We provide a consistent and comprehensive development approach. We also incorporated best practices learned from other game development platforms. More than anything, however, we emphasized and observed two key architectural goals. Performance and power consumption were at the core of every architectural decision – as described in the &lt;a href="http://blogs.msdn.com/b/b8/archive/2012/07/23/hardware-accelerating-everything-windows-8-graphics.aspx" target="_blank"&gt;Hardware Accelerating Everything: Windows 8 Graphics&lt;/a&gt; blog post. Developing games on Windows 8 rocks because the entire platform was designed to deliver fast and fluid entertainment experiences. &lt;/p&gt;  &lt;h3&gt;C++ with DirectX is the preferred development language for games&lt;/h3&gt;  &lt;p&gt;The Windows Runtime provides a rich set of APIs that expose all the new devices and sensors in a convenient, consistent way, and simplifies Windows event handling. There’s a single Windows SDK so every API you need to develop a Windows Store game is available in Microsoft Visual Studio 2012. For the most high-fidelity and immersive experiences, you’ll want to &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465149.aspx" target="_blank"&gt;use the Windows 8 DirectX APIs to build 3D games&lt;/a&gt;. This is the easiest version of DirectX to develop with, and it supports a wide range of graphics feature levels, from DirectX 9.1 to all the latest hardware features exposed in DirectX 11.1, allowing you to tailor your game to every PC from power-efficient ARM-based portable Windows 8 tablet PCs to overclocked multi-GPU gamer rigs.&lt;/p&gt;  &lt;p&gt;If you’re comfortable with a particular development language, you can use a lot of your existing skills and experience in Windows 8. Windows Store games can be developed in a number of technology combinations, depending on the type of game you’re developing and your preference. You’re not going to be forced or constrained to one syntax or model. Managed code developers can build great, smooth 2D games with XAML that leverage the strength and features of the Windows Store platform. If you’re a web developer, you can leverage your existing web and web game development skills to make a game that can be monetized through the Windows Store. For 3D interactive games, we recommend you use C++ with DirectX (and optionally XAML), which will be the main focus of the rest of this article.&lt;/p&gt;  &lt;h3&gt;Game development components&lt;/h3&gt;  &lt;p&gt;Windows 8 offers built-in game technology that ships with every version of the OS and resides on every PC so you don’t have to worry about distributing it or manage multiple versions. There’s no need to find, download and install additional components.&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8206.awesome_5F00_game2_5F00_51B74335.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Windows 8 game development components and libraries" border="0" alt="Windows 8 game development components and libraries" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3010.awesome_5F00_game2_5F00_thumb_5F00_37E30D06.png" width="600" height="230" /&gt;&lt;/a&gt;&lt;i&gt;Figure 1: The Windows 8 game development components and libraries&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;From graphics, audio and input, to file I/O, scheduling, math and networking – each component is accessible in the development language of your choice. Lower level components offer more flexibility, resource management and performance but may require additional code to comprehensively control processing and the flow of data it requires. With C++, you have a direct line to the GPU, CPU and low-level services of the Windows 8 platform, allowing you to write high performance code. With the new C++/CX language extensions, the syntax approaches the simplicity of C#. You get transparent object management via reference counting, and yet there’s no runtime layer, garbage collection or just-in-time compilation behaviors that could compromise the smooth performance of your game. &lt;/p&gt;  &lt;p&gt;For 3D and 2D graphics, media, imaging and many of the other gaming components – the Windows 8 DirectX technologies provide a comprehensive set of APIs, components and libraries to build upon. Check out &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/jj554502.aspx" target="_blank"&gt;Getting started with DirectX game development&lt;/a&gt; for a comprehensive overview. The new Windows 8 graphics stack is better integrated, making Direct2D, Direct3D, DirectVideo and DirectCompute components easier to use together and requiring fewer duplicated resources than before. We’ve also added built-in support for the Xbox controllers with the XInput library. To learn more about it see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452799.aspx" target="_blank"&gt;Working with Input and controls in your DirectX game&lt;/a&gt;. The improved APIs for audio and sound mixing with XAudio2 are covered in the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452794.aspx" target="_blank"&gt;Working with audio in your DirectX game&lt;/a&gt; section, and simplified math functions and types are covered in the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/ee415571.aspx" target="_blank"&gt;DirectXMath programming guide&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;One of the greatest advantages of the DirectX/C++ development approach is that you can reuse significant amounts of your code to create a Windows Store game (and Windows Desktop game), a Windows Phone game, and an Xbox 360 game. The DirectX APIs are relevant to all Microsoft gaming platforms. Everything you’ll need to develop a great Windows game is included in the Runtime, the Windows SDK and Visual Studio 2012. For info about the legacy DirectX SDK, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275.aspx" target="_blank"&gt;Where is the DirectX SDK?&lt;/a&gt; There are several additional development models available in Windows 8. A hybrid model that supports &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx" target="_blank"&gt;DirectX and XAML interop&lt;/a&gt; provides the best control and performance and the convenience of the WinRT UI toolkit. &lt;/p&gt;  &lt;h3&gt;Development tools&lt;/h3&gt;  &lt;p&gt;We provide a great set of tools to meet the demands of Windows Store game developers. Visual Studio 2012 includes a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br229582.aspx" target="_blank"&gt;template for DirectX Windows Store apps&lt;/a&gt; that gives you a head start in developing for Direct3D. The &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465033.aspx" target="_blank"&gt;template code&lt;/a&gt; provides the basic view provider infrastructure and window support, and references to all the necessary headers and components. There are other templates to explore that will make sure you are using best practices no matter which game development model you choose. &lt;/p&gt;  &lt;p&gt;Additionally, new features in Visual Studio 2012 have been added to improve game development, debugging and profiling. Investments in Visual Studio 2012 &lt;a href="http://msdn.microsoft.com/en-us/library/bb386063(v=vs.110).aspx#BKMK_GraphicsTools" target="_blank"&gt;Graphics Tools&lt;/a&gt; were made to ensure that graphics application development is seamlessly integrated. Work with 3D models, view textures and images, or create, edit and compile HLSL shaders without ever leaving the familiar IDE interface. &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh315751.aspx" target="_blank"&gt;Debugging graphics intensive DirectX applications&lt;/a&gt; in Visual Studio 2012 is now more intuitive with the integration of graphics API capture and playback features (previously known as Windows PIX). &lt;/p&gt;  &lt;h3&gt;Samples and tutorials&lt;/h3&gt;  &lt;p&gt;These samples provide a great range of source code examples to get you started on your game development quickly. Each sample focuses on a particular technology or technique. The tutorials and samples were developed with a progression in mind. They are in logical order beginning with the sparsest amount of code and simplest approach to help you get started. Each additional sample adds to the previous sample with one or two additional concepts until an entire game is created. &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh994935.aspx" target="_blank"&gt;Writing Code for DirectX and C++ Windows Store apps&lt;/a&gt; explains some of the things you need to know about writing DirectX and C++ code for Windows Store apps. &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-Tutorial-Sample-08667fb0" target="_blank"&gt;Direct3D Tutorial&lt;/a&gt;: This five step tutorial shows how to initialize Direct3D, draw to the surface, and display updates to the surface using the swap chain. The “spinning cube” displayed by this sample is extended by other Direct3D samples, so this is a great place to start if you’re new to the Direct3D APIs.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Simple-Direct3D-Touch-f98db97e" target="_blank"&gt;DirectX Touch Sample&lt;/a&gt;: This shows very minimal touch support added to the spinning cube from D3DTutorial. Specifically, this shows how to connect your Direct3D animation updates to the touch events provided by the Windows Runtime. See the Bump Mapping sample for pinch-to-zoom navigation.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-sprite-sample-97ae6262" target="_blank"&gt;Direct3D Sprite Sample&lt;/a&gt;: This provides a Direct3D implementation of sprite batch behaviors, similar to the XNA SpriteBatch API. Sprites are 2D bitmaps that can be transformed and managed independently in a 3D scene, typically used in 2D games or to represent computationally expensive or distant objects in 3D games.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-Resource-Loading-25406148" target="_blank"&gt;Resource Loading Sample&lt;/a&gt;: This demonstrates an approach for loading resources and assets like shaders, textures, and meshes. (Note that each content type has an associated build rule in the project. You can add your own content processor apps, and build your own rules to invoke them.)&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-bump-mapping-619d8d23" target="_blank"&gt;Direct3D Bump Mapping Sample&lt;/a&gt;: This demonstrates bump mapping using a normal map and per-pixel lighting. The sample provides code for Surface-shaded lighting of an object using a normal map and a color texture. It also implements a very basic pinch-to-zoom control without the gesture recognizer.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-Post-Processing-3fd1edb8" target="_blank"&gt;Direct3D Post-Processing Sample:&lt;/a&gt; This demonstrates post-processing the simple rotating cube scene using down-scaled intermediate buffers in a Windows Store C++ app with Direct3D. It demonstrates the use of two different shaders depending on the feature level of the hardware. The intermediate render target can be modified to render to a smaller surface to improve performance, and then scale up to the final native resolution of the device for high quality.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Basic-Audio-Sample-9a5bb0b7" target="_blank"&gt;AUDIO2 Audio File Playback Sample&lt;/a&gt;: This sample app shows how to incorporate the XAudio2 APIs for low-latency interactive sound effects into your DirectX game for a better aural experience.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Simple-XInput-Controller-77c4b8e5" target="_blank"&gt;XINPUT Game Controller Sample:&lt;/a&gt;&lt;b&gt; &lt;/b&gt;This shows how to add Xbox controller support to your DirectX game. It reads input from an Xbox game controller and displays data about the analog stick movements and button presses. It shows how to get input state from an attached controller and draw to the display using Direct2D and DirectWrite.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-111-Simple-Stereo-9b2b61aa" target="_blank"&gt;Direct3D Stereoscopic 3D Sample:&lt;/a&gt; Windows 8 supports stereo 3D as a core OS feature. This app shows how to incorporate stereoscopic 3D into your DirectX game. It also demonstrates how to respond to system stereo changes in Direct3D.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Licensing-API-Sample-19712f1a" target="_blank"&gt;Trials and in-app purchases&lt;/a&gt; are so important to the success of games, so this sample demonstrates how to use the licensing API provided by the Windows Store to determine the license status of a game or a feature that is enabled by an in-app purchase.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The following are end-to-end samples that combine the individual techniques into full games:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Metro-style-DirectX-7c64aa8d" target="_blank"&gt;DirectX Simple 3D Shooting Game&lt;/a&gt;: This end-to-end sample app and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh780567.aspx" target="_blank"&gt;comprehensive code walkthrough&lt;/a&gt; shows how to incorporate various control types and DirectX techniques in a simple first-person shooting gallery game. If you’re comfortable with the basics of all the individual technique samples, this is a good place to see all the components of a Windows Store Direct3D game in action. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/Metro-style-DirectX-18f98448" target="_blank"&gt;XAML DirectX Simple 3D Shooting Game&lt;/a&gt;: This demonstrates the basic end-to-end implementation of a simple first person 3-D game using DirectX (Direct3D 11.1, Direct2D, XInput, and XAudio2) and XAML in a C++ app. Direct3D is used to render the 3D content and XAML is used for the heads-up display and game state messages.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/windowsapps/DirectX-Marble-Maze-Game-e4806345" target="_blank"&gt;DirectX Marble Maze Game Sample&lt;/a&gt;: This end-to-end game app is a simple labyrinth game where the player is challenged to roll a marble through a maze of pitfalls using tilt controls. It demonstrates how to fit all the game components into a single application. We’ve also provided some rich guidance around this app in the form of a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br230257(v=VS.85).aspx" target="_blank"&gt;complete code walkthrough&lt;/a&gt;.&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Techniques for developing games&lt;/h3&gt;  &lt;p&gt;Several development patterns, best practices and techniques that are particularly relevant to game development are worth pointing out:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh994923.aspx" target="_blank"&gt;Targeting different Direct3D feature levels&lt;/a&gt; helps you understand how to optimize across many devices that have different levels of graphics performance. This will enable you to reach a wider audience for your Windows Store game built for Windows using DirectX with C++.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh994919.aspx" target="_blank"&gt;Asynchronous programming&lt;/a&gt; ensures your game takes advantage of multiple cores and hyper-threaded CPUs. Your game’s graphics, audio, logic, file I/O and networking can all be parallelized for best performance and battery life.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465290" target="_blank"&gt;Use thread pool parallelization&lt;/a&gt; for Windows Store games instead of traditional threading APIs (such as CreateThread). The task model is especially important for rendering and ensuring a responsive UI, as described in this &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx" target="_blank"&gt;post&lt;/a&gt;.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/jj262112.aspx" target="_blank"&gt;Supporting screen orientation&lt;/a&gt;, covers screen rotation and DPI scaling of content and input for DirectX applications. This helps make sure your game works well on various screen resolutions.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452773.aspx" target="_blank"&gt;Adding mouse move/look controls to your game&lt;/a&gt; explains a traditional mouse-like navigation technique that has been adapted to add touch for the Windows Store development model. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh994925.aspx" target="_blank"&gt;Developing mouse controls&lt;/a&gt; discusses the implementation of relative mouse controls, which hides the system cursor and returns relative screen coordinates rather than absolute values.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452788.aspx" target="_blank"&gt;Game publishing requirements&lt;/a&gt; provides Windows 8 game developers with info about the tools and support for common game publishing scenarios, such as ratings certification and packaging. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/jj863300.aspx" target="_blank"&gt;Supporting Windows RT and ARM processors&lt;/a&gt; gets your DirectX Windows Store game up and running on Windows RT devices, targeting Direct3D feature level 9_1 and compiling an ARM package.&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Using middleware to reduce development time or cost&lt;/h3&gt;  &lt;p&gt;Developing high quality professional games can be costly. Developing games for multiple platforms can be complex, error prone, and even more costly. Many established game studios build tools and develop production technologies that make up their game development process or “pipeline.” These investments help studios leverage their game assets between different games and platforms. Rendering engines, user interface tool kits, visibility occlusion, physics simulators, audio video authoring, animation interpolation and artificial intelligence are just a few of the technology categories typically involved in game development. Some gaming technologies can take many years to develop and fine-tune.&lt;/p&gt;  &lt;p&gt;Proprietary gaming pipelines are incredibly valuable and many studios consider their investments as strategic as the games they make. Not everyone can afford the time or cost of developing a pipeline however. Luckily, third-party vendors offer end-to-end game development pipelines or individual technology libraries that provide these capabilities. Since Windows 8 launched, many gaming middleware vendors have transitioned their offerings to the new Windows Store app model. Using these products will get your game in the Windows Store much faster and with much less risk. As time progresses, we expect more vendors to announce and ship products for Windows Store game development. The following (in alphabetical order) is a compilation of third-party gaming middleware vendors that (at the time of writing) have announced or delivered versions of their product that support Windows 8 game development. &lt;/p&gt;  &lt;div align="center"&gt;   &lt;table class="b8table" border="0" cellspacing="0" cellpadding="3" align="center"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Appcelerator &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;appMobi {!}&lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="217"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Audiokinetic Wwise&lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Autodesk Scaleform &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Cocos2d &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="217"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Epic Unreal Engine 3 &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Exit Games Photon Server &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Fortumo Mobile Payments &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="217"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Firelight Technologies FMOD &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;GameSalad Creator &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Havok Physics &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="217"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Havok Vision Engine &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;MonoGame &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Ogre Rendering Engine &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="217"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;NVIDIA PhysX &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Scirra Construct 2 &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;SharpDX &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="217"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;ShiVa3D &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;SlimDX &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Unigine Engine &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="217"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Unity 3d &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="208"&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;Yoyo Games GameMaker&lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="208"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="217"&gt;&amp;#160;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb200104(v=xnagamestudio.40).aspx" target="_blank"&gt;Microsoft’s XNA Game Studio&lt;/a&gt; is a game development pipeline that targets the Xbox 360, Windows Phone and Windows. However, it’s not compatible with Windows Store game development, (although XNA games are supported as Windows 8’s desktop apps). DirectX development with Visual C++/CX borrows many patterns and practices from XNA, and shares many conceptual similarities. So many XNA game developers will find it relatively easy to transition to DirectX and C++ development than ever before. Alternatively, we have seen developers successfully use the open source &lt;a href="http://monogame.codeplex.com/" target="_blank"&gt;MonoGame&lt;/a&gt; library that replicates many of the XNA Game Studio capabilities. Several articles have been written about leveraging assets created with XNA for games targeting the Windows Store. Here’s a &lt;a href="http://blogs.msdn.com/b/tarawalker/archive/2012/12/04/windows-8-game-development-using-c-xna-and-monogame-3-0-building-a-shooter-game-walkthrough-part-1-overview-installation-monogame-3-0-project-creation.aspx" target="_blank"&gt;link&lt;/a&gt; to more info on the subject.&lt;/p&gt;  &lt;h3&gt;Additional resources for developing games&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;The documentation has a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh452744.aspx" target="_blank"&gt;dedicated game development area on MSDN&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;The game-centric sessions, slides decks and recordings of talks that were given at &lt;a href="http://channel9.msdn.com/Events/Build/2012?sort=sequential&amp;amp;direction=desc&amp;amp;term=game" target="_blank"&gt;//build/ 2012&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;The game-centric sessions, slides decks and recordings of talks that were given at &lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/03/28/game-developer-conference-2012.aspx" target="_blank"&gt;GDC 2012&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;The game-centric sessions, slides decks and recordings of talks that were given at &lt;a href="http://channel9.msdn.com/Events/Build/BUILD2011?sort=sequential&amp;amp;direction=desc&amp;amp;term=game" target="_blank"&gt;//build/ 2011&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Help and support is available on The Developer Center which has a &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wingameswithdirectx/threads" target="_blank"&gt;dedicated forum for game development&lt;/a&gt; for game developers like you who can provide answers when you need them&lt;/li&gt;    &lt;li&gt;The &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectX Toolkit&lt;/a&gt; is a collection of helper classes for writing Direct3D 11 C++ code&lt;/li&gt;    &lt;li&gt;Other great resources include &lt;a href="http://blogs.msdn.com/b/chuckw/" target="_blank"&gt;Chuck Walbourn’s blog&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/shawnhar/" target="_blank"&gt;Shawn Hargreaves’ blog&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Summary&lt;/h2&gt;  &lt;p&gt;Windows 8 reimagines PCs and with new form factors, innovative technologies and lucrative commerce models that are perfect for gaming. The platform represents a green-field of opportunity for those who take advantage of it. The Windows Store has several thousand games at the time of writing and that number grows daily. The goal of this post was to help you understand what it would take to create a great Windows Store game of your own to leverage the possibilities. The information was meant to clarify how Windows 8 can make game development easier, more creative, innovative and profitable. We’ve reviewed what tools, technologies and services are available on the platform and what third-party technologies are available. As we head out to the annual &lt;a href="http://gdconf.com/" target="_blank"&gt;Game Developer Conference&lt;/a&gt; in San Francisco, look to this post for guidance as you develop Windows Store games.&lt;/p&gt;  &lt;p&gt;Game On! &lt;/p&gt;  &lt;p&gt;Shai Hinitz, Sr. Program Manager&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10404314" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+Store+apps/">Windows Store apps</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/GDC/">GDC</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+8+games/">Windows 8 games</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+Store+games/">Windows Store games</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/gaming/">gaming</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+games/">Windows games</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/games/">games</category></item><item><title>Alive with Activity, Part 3: Push notifications and Windows Azure Mobile Services</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/03/13/alive-with-activity-part-3-push-notifications-and-windows-azure-mobile-services.aspx</link><pubDate>Wed, 13 Mar 2013 22:51:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10402141</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10402141</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/03/13/alive-with-activity-part-3-push-notifications-and-windows-azure-mobile-services.aspx#comments</comments><description>&lt;p&gt;In Part 1 of this series we explored what “aliveness” means to a user and how apps participate in creating that experience. In Part 2 we looked at how to write and debug web services to support periodic updates for live tiles. Here in Part 3 we’ll complete the story by understanding how to deliver tile updates, toasts, and raw notifications to specific client devices on demand through the Windows Push Notification Service (WNS), and how Windows Azure Mobile Services simplifies the whole process.&lt;/p&gt;  &lt;h2&gt;Push notifications&lt;/h2&gt;  &lt;p&gt;Periodic updates, as we saw in Part 2, are initiated from the client side and provide a polling&lt;i&gt; &lt;/i&gt;or “pull” method of updating a tile or badge. “Push” notifications happen when a service directly sends an update to a device, where that update can be specific to a user, an app, and even a secondary tile.&lt;/p&gt;  &lt;p&gt;Unlike polling, push notifications can happen at any time with much greater frequency, though be aware that Windows will throttle the amount of push notification traffic on a device if it’s on battery power, in connected standby mode, or if notification traffic becomes excessive. This means there is no guarantee that all notifications will be delivered (especially if the device is turned off).&lt;/p&gt;  &lt;p&gt;So avoid thinking that you can use push notifications to implement a clock tile or other tile gadgets with a similar kind of frequency or time resolution. Instead, think about how you can use push notifications to connect tiles and notifications to a back-end service that has interesting and meaningful information to convey to the user, which invites them to re-engage with your app.&lt;/p&gt;  &lt;p&gt;Before we dive into the details, understand that there are two distinct kinds of push notifications:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;XML updates that contain tile or badge updates, or toast notification payloads: Windows can process such push notifications and issue the update or toast on behalf of an app. An app can also handle these notifications directly, if desired.&lt;/li&gt;    &lt;li&gt;Binary or &lt;i&gt;raw&lt;/i&gt; notifications that contain whatever data the service wants to send: these &lt;i&gt;must&lt;/i&gt; be handled by app-specific code because Windows won’t know what to do with the data otherwise. See &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/Hh761463.aspx" target="_blank"&gt;Guidelines and checklist for raw notifications&lt;/a&gt; for details such as size limits (5KB) and encoding (base64).&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In both cases, a running (foreground) app can handle push notifications directly through the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br241283.aspx" target="_blank"&gt;PushNotificationChannel&lt;/a&gt; class and its &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.pushnotifications.pushnotificationchannel.pushnotificationreceived.aspx" target="_blank"&gt;PushNotificationReceived&lt;/a&gt; event. For XML payloads, the app can modify the contents, change tags, and so forth, before issuing it locally (or choosing to ignore it). For raw notifications, the app processes the contents and then decides which notifications to issue, if any.&lt;/p&gt;  &lt;p&gt;If the app is suspended or not running, it can also provide a background task for this same purpose. The app must request and be granted lock screen access, which then allows such app-specific code to run when a notification is received.&lt;/p&gt;  &lt;p&gt;A background task typically does one or two things when the notification arrives. First, it might save some relevant information from the notification into local app data, where the app can retrieve it when it’s next activated or resumed. Second, the background task can issue local tile and badge updates and/or toast notifications.&lt;/p&gt;  &lt;p&gt;To understand raw notifications better, consider a typical email app. When its back-end service detects new messages for a user, it sends a raw push notification to WNS that contains a number of email message headers. The service does so using a &lt;i&gt;channel URI&lt;/i&gt; that’s connected to the specific app on that user’s specific device.&lt;/p&gt;  &lt;p&gt;WNS then attempts to push that notification to the client. Assuming it succeeds, Windows receives that notification and looks for the app that’s associated with the channel URI in question. If it cannot find a suitable app, the notification is ignored. If an app exists and it’s running, Windows fires the &lt;i&gt;PushNotificationReceived&lt;/i&gt; event, otherwise Windows looks for and invokes an available background task for that app.&lt;/p&gt;  &lt;p&gt;Either way the raw notification ends up in the hands of some app code, which then processes the data, issues a badge update to the app tile to indicate the number of new messages, and issues up to five cycling tile updates with message headers. The app can also issue toast notifications for each new message that’s arrived, or at least one that indicates there’s new mail.&lt;/p&gt;  &lt;p&gt;As a result, toasts tell the user that new email has arrived, and the app’s tile on the Start screen provides a quick and immediate view of new mail activity.&lt;/p&gt;  &lt;p&gt;For more info about these client-side event handlers and background tasks, see the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Raw-notifications-sample-3bc28c5d" target="_blank"&gt;Raw notifications sample&lt;/a&gt;, the &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/05/24/being-productive-in-the-background-background-tasks.aspx" target="_blank"&gt;Being productive in the background—background tasks&lt;/a&gt; post on this blog, and the &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=28999" target="_blank"&gt;Background networking whitepaper&lt;/a&gt;. For our purposes here, let’s turn now to the service side of the story.&lt;/p&gt;  &lt;h2&gt;Working with Windows Push Notification Service (WNS)&lt;/h2&gt;  &lt;p&gt;Through the cooperation of Windows, apps, services, and WNS, it’s possible to deliver user-specific data to a specific app tile (or toast or raw notification handler) on a specific device for a specific user. The relationships between all these pieces is shown below.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8611.alive_2D00_with_2D00_activity_2D00_3_5F00_graph_5F00_52EC8A0B.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="WNS cooperation flowchart" border="0" alt="Flow chart showing how Windows, apps, services and WNS work together to deliver data to a specific app tile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/6457.alive_2D00_with_2D00_activity_2D00_3_5F00_graph_5F00_thumb_5F00_4AF4E7A9.png" width="700" height="347" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Clearly, some wiring is necessary to make all this work harmoniously:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;You (the developer) register the app in the Windows Store to use push notifications. This provides an SID and client secret that the service uses to authenticate with WNS (these bits should never be stored on client devices for security purposes).&lt;/li&gt;    &lt;li&gt;At runtime, the app requests a WNS channel URI from Windows for each of its live tiles (primary and secondary), or one for raw notifications. An app must also refresh these channel URIs every 30 days, for which you can use another background task.&lt;/li&gt;    &lt;li&gt;The app’s service provides a URI through which the app can upload those channel URIs along with any data that describes its use (such as location for weather updates or a specific user account and activity). Upon receipt, the service stores those channel URIs and associated data for later use.&lt;/li&gt;    &lt;li&gt;The service monitors its backend for changes that apply to each particular user/device/app/tile combination. When the service detects a condition that triggers a notification for a particular channel, it builds the content of that notification (XML or raw), authenticates itself with WNS using the SID and client secret, and then sends the notification to WNS along with the channel URI.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Let’s look at each step in detail. (And just as a preview, if dealing with HTTP requests makes you nervous, Windows Azure Mobile Services relieves you from many of the details, as we’ll see.)&lt;/p&gt;  &lt;h3&gt;App registration with the Windows Store&lt;/h3&gt;  &lt;p&gt;To obtain the SID and client secret for your service, refer to &lt;a href="http://msdn.microsoft.com/library/windows/apps/hh465407.aspx" target="_blank"&gt;How to authenticate with the Windows Push Notification Service (WNS)&lt;/a&gt; on the Windows Developer Center. The SID is what identifies your app with WNS, and the client secret is what your service uses to tell WNS that it’s allowed to send notifications for your app. Again, these should only be stored in the service.&lt;/p&gt;  &lt;p&gt;Note that Step 4 in &lt;a href="http://msdn.microsoft.com/library/windows/apps/hh465407.aspx" target="_blank"&gt;How to authenticate with the Windows Push Notification Service (WNS)&lt;/a&gt;, “Send the cloud server's credentials to WNS,” is something you do only when your service sends a push notification. We’ll come back to that shortly, because at this stage your service lacks the key piece that it needs to send a notification, namely a channel URI.&lt;/p&gt;  &lt;h3&gt;Obtaining and refreshing channel URIs&lt;/h3&gt;  &lt;p&gt;The client app obtains channel URIs at runtime through the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.pushnotifications.pushnotificationchannelmanager.aspx" target="_blank"&gt;Windows.Networking.PushNotifications.PushNotificationChannelManager&lt;/a&gt; object. This object has only two methods:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;i&gt;createPushNotificationChannelForApplicationAsync&lt;/i&gt;: creates a channel URI for the app’s primary tile as well as toasts and raw notifications.&lt;/li&gt;    &lt;li&gt;&lt;i&gt;createPushNotificationChannelForSecondaryTileAsync:&lt;/i&gt; creates a channel URI for a specific secondary tile identified by a &lt;i&gt;tileId&lt;/i&gt; argument.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The result of both async operations is a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.pushnotifications.pushnotificationchannel.aspx" target="_blank"&gt;PushNotificationChannel&lt;/a&gt; object. This object contains the channel URI in its &lt;i&gt;Uri &lt;/i&gt;property, along with an &lt;i&gt;ExpirationTime&lt;/i&gt; to indicate the deadline for refreshing that channel. A &lt;i&gt;Close &lt;/i&gt;method specifically terminates the channel if needed, and most importantly is the &lt;i&gt;PushNotificationReceived&lt;/i&gt; event, which is again what’s fired when the app is in the foreground and a push notification is received through this channel.&lt;/p&gt;  &lt;p&gt;The lifetime of a channel URI is 30 days, after which WNS rejects any requests made for that channel. App code thus needs to refresh those URIs with the &lt;i&gt;create&lt;/i&gt; methods above at least once every 30 days and send those URIs to its service. Here’s a good strategy:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;On first launch, request a channel URI and save the string in the &lt;i&gt;Uri &lt;/i&gt;property in your local app data. Because channel URIs are specific to a device, do not store them in your roaming app data.&lt;/li&gt;    &lt;li&gt;On subsequent launches, request a channel URI again and compare it to the one previously saved. If it’s different, send it to the service, or send it and let the service replace an older one if necessary.&lt;/li&gt;    &lt;li&gt;Also perform the previous step in your app’s &lt;i&gt;Resuming &lt;/i&gt;handler (see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh770837.aspx" target="_blank"&gt;Launching, resuming, and multitasking&lt;/a&gt; in the docs), because it’s possible that the app might have been suspended for more than 30 days.&lt;/li&gt;    &lt;li&gt;If you’re concerned the app won’t be run within 30 days, implement a background task with a maintenance trigger to run every few days or once a week. For details, refer again to &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/05/24/being-productive-in-the-background-background-tasks.aspx" target="_blank"&gt;Being productive in the background—background tasks&lt;/a&gt;; the background task in this case will just execute the same code as the app to request a channel and send it to your service.&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Sending channel URIs to the service&lt;/h3&gt;  &lt;p&gt;Typically, push notification channels work with user-specific updates like email status, instant messages, and other personalized information. It’s unlikely that your service will need to broadcast the same notification to every user and/or every tile. For this reason, the service needs to associate each channel URI with more specific information. For an email app, the user’s id is paramount, as that would specify the account to check. A weather app, on the other hand, would likely associate each channel URI with a specific latitude and longitude, such that each tile (primary and secondary) would reflect a distinct location.&lt;/p&gt;  &lt;p&gt;The app, then, must include these details when it sends a channel URI to its service, and the service must store them for later use.&lt;/p&gt;  &lt;p&gt;Where user identity is concerned, it’s best for the app to authenticate the user with the service separately, using service-specific credentials or through an OAuth provider such as Facebook, Twitter, Google, or the user’s Microsoft Account (using OAuth is helpful with Windows Azure Mobile Services, as we’ll see later). If for some reason that’s not possible, be sure to encrypt any user id you send to the service or make sure to send it over HTTPS.&lt;/p&gt;  &lt;p&gt;Whatever the case, how you send all this information to your service (in headers, through data in the message body, or as parameters on the service URI) is up to you. This part of the communication is strictly between the app and its service.&lt;/p&gt;  &lt;p&gt;As a simple example, let’s say we have a service with a page called &lt;i&gt;receiveuri.aspx&lt;/i&gt; (as we’ll see in the next section), the full address of which is in a variable called &lt;i&gt;url&lt;/i&gt;. The following code requests a primary channel URI from Windows for the app and posts it to that page via HTTP. (This code derived and simplified from the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Push-and-periodic-de225603" target="_blank"&gt;Push and periodic notifications client side sample&lt;/a&gt; where the &lt;i&gt;itemId &lt;/i&gt;variable, defined elsewhere, is used to identify secondary tiles; the sample also has a C++ variant, not shown here):&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;:&lt;/p&gt;  &lt;div&gt;&amp;#160; &lt;/div&gt;  &lt;blockquote&gt;   &lt;div id="codeSnippetWrapper"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;Windows.Networking.PushNotifications.PushNotificationChannelManager&lt;br /&gt;    .createPushNotificationChannelForApplicationAsync()&lt;br /&gt;    .done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (channel) {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//Typically save the channel URI to appdata here.&lt;/span&gt;&lt;br /&gt;        WinJS.xhr({ type: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;, url:url,&lt;br /&gt;            headers: { &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Content-Type&amp;quot;&lt;/span&gt;: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt; },&lt;br /&gt;            data: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;channelUri=&amp;quot;&lt;/span&gt; + encodeURIComponent(channel.uri) &lt;br /&gt;                + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;amp;itemId=&amp;quot;&lt;/span&gt; + encodeURIComponent(itemId)&lt;br /&gt;        }).done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (request) {&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;//Typically update the channel URI in app data here.&lt;/span&gt;&lt;br /&gt;        }, &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (e) {&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;//Error handler&lt;/span&gt;&lt;br /&gt;        });&lt;br /&gt;    });&lt;br /&gt;&lt;/pre&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/div&gt;
&lt;/blockquote&gt;

&lt;div&gt;&lt;strong&gt;C#:&lt;/strong&gt;&lt;/div&gt;

&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&amp;#160; &lt;blockquote&gt;
    &lt;div id="codeSnippetWrapper"&gt;
      &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; Windows.Networking.PushNotifications;&lt;br /&gt;&lt;br /&gt;PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();&lt;br /&gt;HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);&lt;br /&gt;webRequest.Method = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;;&lt;br /&gt;webRequest.ContentType = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] channelUriInBytes = Encoding.UTF8.GetBytes(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;ChannelUri=&amp;quot;&lt;/span&gt; + WebUtility.UrlEncode(newChannel.Uri) + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;amp;ItemId=&amp;quot;&lt;/span&gt; + WebUtility.UrlEncode(itemId));&lt;br /&gt;&lt;br /&gt;Task&amp;lt;Stream&amp;gt; requestTask = webRequest.GetRequestStreamAsync();&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (Stream requestStream = requestTask.Result)&lt;br /&gt;{&lt;br /&gt;    requestStream.Write(channelUriInBytes, 0, channelUriInBytes.Length);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
  &lt;/blockquote&gt;
The following ASP.NET code is a basic implementation of a &lt;i&gt;receiveuri.aspx&lt;/i&gt; page that processes this HTTP POST, making sure it received a valid channel URI, a user, and some identifier for the item.&lt;/div&gt;

&lt;p&gt;I emphasize the “basic” nature of this code because, as you can see, the &lt;i&gt;SaveChannel&lt;/i&gt; function simply writes the contents of the request into a fixed text file, which clearly won’t scale beyond a single user! A real service, of course, would employ a database for this purpose, but the structure here will be similar.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&amp;lt;%@ Page Language=&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; AutoEventWireup=&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;true&amp;quot;&lt;/span&gt; %&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script runat=&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//Output page header&lt;/span&gt;&lt;br /&gt;    Response.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;!DOCTYPE html&amp;gt;\n&amp;lt;head&amp;gt;\n&amp;lt;title&amp;gt;Register Channel URI&amp;lt;/title&amp;gt;\n&amp;lt;/head&amp;gt;\n&amp;lt;html&amp;gt;\n&amp;lt;body&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//If called with HTTP GET (as from a browser), just show a message.&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (Request.HttpMethod == &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        Response.StatusCode = 400;&lt;br /&gt;        Response.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;p&amp;gt;This page is set up to receive channel URIs from a push notification client app.&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;        Response.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (Request.HttpMethod != &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;) {&lt;br /&gt;        Response.StatusCode = 400;&lt;br /&gt;        Response.Status = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;400 This page only accepts POSTs.&amp;quot;&lt;/span&gt;;&lt;br /&gt;        Response.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;p&amp;gt;This page only accepts POSTs.&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;        Response.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;quot;&lt;/span&gt;);        &lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//Otherwise assume a POST and check for parameters    &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//channelUri and itemId are the values posted from the Push and Periodic Notifications Sample in the Windows 8 SDK&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (Request.Params[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;channelUri&amp;quot;&lt;/span&gt;] != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; Request.Params[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;itemId&amp;quot;&lt;/span&gt;] != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// Obtain the values, along with the user string&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; uri = Request.Params[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;channelUri&amp;quot;&lt;/span&gt;];&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; itemId = Request.Params[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;itemId&amp;quot;&lt;/span&gt;];&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; user = Request.Params[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;LOGON_USER&amp;quot;&lt;/span&gt;];&lt;br /&gt;                 &lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;//TODO: validate the parameters and return 400 if not.&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;//Output in response&lt;/span&gt;&lt;br /&gt;            Response.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;p&amp;gt;Saved channel data:&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;channelUri = &amp;quot;&lt;/span&gt; + uri + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;br/&amp;gt;&amp;quot;&lt;/span&gt; + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;itemId = &amp;quot;&lt;/span&gt; + itemId + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;user = &amp;quot;&lt;/span&gt; + user + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;//The service should save the URI and itemId here, along with any other unique data from the app such as the user;&lt;/span&gt;&lt;br /&gt;            SaveChannel(uri, itemId, user);&lt;br /&gt;&lt;br /&gt;            Response.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;    {&lt;br /&gt;        Trace.Write(ex.Message);&lt;br /&gt;        Response.StatusCode = 500;&lt;br /&gt;        Response.StatusDescription = ex.Message; &lt;br /&gt;        Response.End();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SaveChannel(String uri, String itemId, String user)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//Typically this would be saved to a database of some kind; to keep this demonstration very simple, we'll just use&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//the complete hack of writing the data to a file, paying no heed to overwriting previous data.&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//If running in the debugger on localhost, this will save to the project folder&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; saveLocation = Server.MapPath(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;.&amp;quot;&lt;/span&gt;) + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;\\&amp;quot; + &amp;quot;&lt;/span&gt;channeldata_aspx.txt&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;;&lt;br /&gt;    string data = uri + &amp;quot;&lt;/span&gt;~&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot; + itemId + &amp;quot;&lt;/span&gt;~&amp;quot; + user;&lt;br /&gt;&lt;br /&gt;    System.Text.ASCIIEncoding encoding = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; System.Text.ASCIIEncoding();&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] dataBytes = encoding.GetBytes(data);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (System.IO.FileStream fs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; System.IO.FileStream(saveLocation, System.IO.FileMode.Create))&lt;br /&gt;    {&lt;br /&gt;        fs.Write(dataBytes, 0, data.Length);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;The code for this service can be found in Chapter 13 of my free ebook, &lt;a href="http://go.microsoft.com/fwlink/?LinkID=269853"&gt;&lt;i&gt;Programming Windows 8 Apps in HTML, CSS, and JavaScript&lt;/i&gt;&lt;/a&gt;&lt;i&gt;, &lt;/i&gt;specifically in the HelloTiles sample of the companion content. It’s designed to work with the client-side SDK sample referenced earlier. If you run HelloTiles in the debugger (Visual Studio 2012 Ultimate or Visual Studio Express 2012 for Web) with the localhost enabled, you’ll have URL like &lt;i&gt;http://localhost:52568/HelloTiles/receiveuri.aspx &lt;/i&gt;that you can paste into the client-side SDK sample. When the sample then makes a request to that URL, you’ll stop on any breakpoints in the service and can step through the code.&lt;/p&gt;

&lt;h3&gt;Sending the notification&lt;/h3&gt;

&lt;p&gt;In a real service, you’ll have some kind of ongoing process that monitors its data sources and sends push notifications to specific users when appropriate. This might happen in a number of ways:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A scheduled job can check for weather alerts for a specific location perhaps once every 15-30 minutes, depending on how often those alerts are issued, and issue push notifications in response.&lt;/li&gt;

  &lt;li&gt;Another service, like a messaging back-end, might make a request to a page on your server when a new message is available. That page can then issue appropriate notification.&lt;/li&gt;

  &lt;li&gt;Users might be interacting with webpages on your server, and their activities trigger push notifications to specific channels.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, there are a number of triggers for push notifications, depending entirely on the nature of your back-end service or website. For the purposes of this article, the same HelloTiles sample service from Chapter 13 of &lt;a href="http://go.microsoft.com/fwlink/?LinkID=269853"&gt;&lt;i&gt;Programming Windows 8 Apps in HTML, CSS, and JavaScript&lt;/i&gt;&lt;/a&gt; has a page called &lt;i&gt;sendBadgeToWNS.aspx&lt;/i&gt; that sends a push notification whenever you visit that page in a browser, using whatever channel URI was saved in the text file earlier. A real service performs some kind of database lookup to obtain channel URIs instead of reading the contents of a file, but again the overall structure is very similar.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ASP.NET Page:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div style="margin: 0em; padding: 0px; width: 100%; height: 200px; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
    &lt;pre id="codeSnippet"&gt;&lt;span&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;sendBadgeToWNS.aspx.cs&amp;quot; Inherits=&amp;quot;sendBadgeToWNS&amp;quot; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;DOCTYPE&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;html&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;head&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;    &lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;Send WNS Update&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;head&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;p&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;Sending badge update to WNS&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;p&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;&amp;#160; &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C# code-behind:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Web;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Web.UI;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Net;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Runtime.Serialization;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Runtime.Serialization.Json;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;partial&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; sendBadgeToWNS : System.Web.UI.Page&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//Load our data that was previously saved. A real service would do a database lookup here&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//with user- or tile-specific criteria.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; loadLocation = Server.MapPath(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;.&amp;quot;&lt;/span&gt;) + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;\\&amp;quot; + &amp;quot;&lt;/span&gt;channeldata_aspx.txt&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;        byte&lt;/span&gt;[] dataBytes;&lt;br /&gt;        &lt;br /&gt;        using (System.IO.&lt;span style="color: rgb(0, 96, 128);"&gt;FileStream&lt;/span&gt; fs = new System.IO.&lt;span style="color: rgb(0, 96, 128);"&gt;FileStream&lt;/span&gt;(loadLocation, System.IO.&lt;span style="color: rgb(0, 96, 128);"&gt;FileMode&lt;/span&gt;.Open))&lt;br /&gt;        {&lt;br /&gt;            dataBytes = new byte[fs.Length];&lt;br /&gt;            fs.Read(dataBytes, 0, dataBytes.Length);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        if (dataBytes.Length == 0)&lt;br /&gt;        {&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        System.Text.&lt;span style="color: rgb(0, 96, 128);"&gt;ASCIIEncoding&lt;/span&gt; encoding = new System.Text.&lt;span style="color: rgb(0, 96, 128);"&gt;ASCIIEncoding&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; data = encoding.GetString(dataBytes);&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] values = data.Split(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Char[] { '~' });&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; uri = values[0]; &lt;span style="color: rgb(0, 128, 0);"&gt;//Channel URI&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; secret = &amp;quot;9ttsZT0JgHAFveYahK1B6jQbvMOIWYbm&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; sid = &amp;quot;&lt;/span&gt;ms-app:&lt;span style="color: rgb(0, 128, 0);"&gt;//s-1-15-2-2676450768-845737348-110814325-22306146-1119600341-293560589-2707026538&amp;quot;;&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//Create some simple XML for a badge update&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; xml = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;?xml version=\&amp;quot;1.0\&amp;quot; encoding=\&amp;quot;utf-8\&amp;quot; ?&amp;gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;        xml += &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;&amp;lt;badge value='alert'/&amp;gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;                    &lt;br /&gt;        PostToWns(secret, sid, uri, xml, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;wns/badge&amp;quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;All we’re doing here is retrieving the channel URI, building the XML payload, and then authenticating with WNS and doing an HTTP POST to that channel URI. The last two steps are done in the &lt;i&gt;PostToWns &lt;/i&gt;function that comes from the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868252.aspx"&gt;QuickStart: Sending a push notification&lt;/a&gt; topic on the Windows Developer Center. I’m omitting a full listing because the bulk of it is just authenticating with WNS via OAuth (at https://login.live.com/accesstoken.srf) using your client secret and SID from the Windows Store. The result of this authentication is an access token that’s then included in the HTTP POST we send to the channel URI:&lt;/p&gt;

&lt;p&gt;C#:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; PostToWns(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; secret, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; sid, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; uri, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; xml, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; type = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;wns/badge&amp;quot;&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// You should cache this access token&lt;/span&gt;&lt;br /&gt;        var accessToken = GetAccessToken(secret, sid);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] contentInBytes = Encoding.UTF8.GetBytes(xml);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// uri is the channel URI&lt;/span&gt;&lt;br /&gt;        HttpWebRequest request = HttpWebRequest.Create(uri) &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; HttpWebRequest;&lt;br /&gt;        request.Method = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;;&lt;br /&gt;        request.Headers.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;X-WNS-Type&amp;quot;&lt;/span&gt;, type);&lt;br /&gt;        request.Headers.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Authorization&amp;quot;&lt;/span&gt;, String.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Bearer {0}&amp;quot;&lt;/span&gt;, accessToken.AccessToken));&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (Stream requestStream = request.GetRequestStream())&lt;br /&gt;            requestStream.Write(contentInBytes, 0, contentInBytes.Length);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; webResponse.StatusCode.ToString();&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (WebException webException)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Implements a maximum retry policy (omitted)&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this example, note that the &lt;i&gt;X-WNS-Type&lt;/i&gt; header in the HTTP request is set to &lt;i&gt;wns/badge &lt;/i&gt;and the &lt;i&gt;Content-Type&lt;/i&gt; header defaults to &lt;i&gt;text/xml&lt;/i&gt;. For tiles, the type should be &lt;i&gt;wns/tile&lt;/i&gt;; toasts use &lt;i&gt;wns/toast&lt;/i&gt;. With raw notifications, use the type &lt;i&gt;wns/raw&lt;/i&gt; and set &lt;i&gt;Content-Type &lt;/i&gt;to &lt;i&gt;application/octet-stream&lt;/i&gt;. For full details on headers, refer to the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx"&gt;Push notification service request and response headers&lt;/a&gt; page in the documentation.&lt;/p&gt;

&lt;h3&gt;Push notification failures&lt;/h3&gt;

&lt;p&gt;Of course, sending an HTTP request like this might not always work, and there are a number of reasons why WNS will respond with something other than a 200 code (success). For specific details, see the “Response code” section of the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx" target="_blank"&gt;Push notification service request and response headers&lt;/a&gt;; here are the more common errors and causes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The channel URI is invalid (404 Not Found) or expired (410 Gone). In these cases the service should remove the channel URI from its database and not make any further requests to it.&lt;/li&gt;

  &lt;li&gt;The client secret and SID might be invalid (401 Unauthorized) or there’s a mismatch between the app’s package ID in its manifest and the one in the Windows Store (403 Forbidden). The best way to ensure that these match is to use the &lt;i&gt;Store &amp;gt; Associate App with Store&lt;/i&gt; menu command in Visual Studio (this command is found on the &lt;i&gt;Project&lt;/i&gt; menu in Visual Studio 2012 Ultimate).&lt;/li&gt;

  &lt;li&gt;The raw notification payload is over 5KB (413 Request Entity Too Large).&lt;/li&gt;

  &lt;li&gt;The client could be offline, in which case WNS will automatically try again, but eventually report a failure. For XML notifications, the default behavior is that push notifications are cached and delivered when the client comes back online. For raw notifications, caching is disabled by default; you can change this by setting the &lt;i&gt;X-WNS-Cache-Policy&lt;/i&gt; header to &lt;i&gt;cache &lt;/i&gt;in the request to the channel URI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For other errors (400 Bad Request), make sure that XML payloads contain UTF-8 encoded text, and that raw notifications are in base64 with the &lt;i&gt;Content-Type&lt;/i&gt; header set to &lt;i&gt;application/octet-stream&lt;/i&gt;. It’s also possible that WNS is throttling delivery because you’re simply trying to send too many push notifications within a specific time period.&lt;/p&gt;

&lt;p&gt;A raw push notification might also be rejected if the app isn’t present on the lock screen and the device is in connected standby. Because Windows blocks raw notifications to non-lock screen apps in this state (and anytime the app isn’t in the foreground), WNS has optimizations to drop notifications that it knows won’t be delivered.&lt;/p&gt;

&lt;h2&gt;Windows Azure Mobile Services&lt;/h2&gt;

&lt;p&gt;Now that we’ve gone through the intricate details of working with push notifications, even omitting the question of storage, you’re probably wondering, “Is there any way to make all this simpler?” Just imagine what it would take to manage potentially thousands or millions of channel URIs for a hopefully large and expanding customer base!&lt;/p&gt;

&lt;p&gt;Fortunately, you’re not the first to ask such questions. Besides third-party solutions such as those offered by Urban Airship, Windows Azure Mobile Services can make your life a whole lot easier.&lt;/p&gt;

&lt;p&gt;Windows Azure Mobile Services, which I’ll just abbreviate as AMS, provides a pre-built solution (basically a number of REST endpoints) for most of the service details we’ve been discussing. A “mobile service” is basically one that manages a database on your behalf and provides library functions to easily send payloads to WNS. An introduction to AMS can be found on &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/08/28/add-cloud-to-your-app-with-windows-azure-mobile-services.aspx" target="_blank"&gt;Add cloud to your app with Windows Azure Mobile Services&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For push notifications in particular, first obtain the client-side library in the &lt;a href="http://go.microsoft.com/fwlink/?LinkId=257545&amp;amp;clcid=0x409" target="_blank"&gt;Windows Azure Mobile Services SDK for Windows 8&lt;/a&gt;. Then refer to &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-push-dotnet/" target="_blank"&gt;Get started with push notifications in Mobile Services&lt;/a&gt; (note that there’s a &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-push-js/" target="_blank"&gt;JavaScript version of the topic&lt;/a&gt; too), which describes how AMS helps you fulfill all the wiring requirements we saw earlier:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;App registration with the Windows Store: Once you obtain the client secret and SID for your app from the Windows Store, save those values in the mobile service configuration. See the “Register your app for the Windows Store” section in the &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-push-dotnet/" target="_blank"&gt;Get started&lt;/a&gt; topic just mentioned.&lt;/li&gt;

  &lt;li&gt;Obtaining and refreshing channel URIs: requesting and managing channel URIs in the app is purely a client-side concern, and is the same as before.&lt;/li&gt;

  &lt;li&gt;Sending channel URIs to the service: this step becomes far easier with AMS. First you create a database table in the mobile service (through the Windows Azure portal). Then the app can simply insert records into that table with channel URIs and any other key information you need to attach. The AMS client library takes care of the HTTP request behind the scenes, and even updates the client-side record with any changes made on the server. Furthermore, AMS can automatically handle authentication through the user’s Microsoft Account or through three other OAuth providers—Facebook, Twitter, or Google—if you’ve registered your app with one of them. See &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users-js/" target="_blank"&gt;Get started with authentication in Mobile Services&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;Sending the notification: within the mobile service, you can attach scripts (written in the variant of JavaScript known as Node.js) to database operations, and also created scheduled jobs in JavaScript. In these scripts, a simple call to the &lt;i&gt;push.wns &lt;/i&gt;object with a channel URI and a payload generates the necessary HTTP request to the channel. It’s also a simple matter to capture push failures and record the response with &lt;i&gt;console.log&lt;/i&gt;. Those logs are easily reviewed on the Windows Azure portal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For extensive details, see these two sample tutorials: &lt;a href="http://code.msdn.microsoft.com/windowsapps/Tile-Toast-and-Badge-Push-90ee6ff1" target="_blank"&gt;Tile, Toast, and Badge Push Notifications using Windows Azure Mobile Services&lt;/a&gt; and &lt;a href="http://code.msdn.microsoft.com/windowsapps/Raw-Notifications-using-adb63a01" target="_blank"&gt;Raw Notifications using Windows Azure Mobile Services&lt;/a&gt;. Here, instead of repeating all those instructions, let’s review a few of the highlights.&lt;/p&gt;

&lt;p&gt;When you set up a mobile service, it will have a specific service URL. This is what you use when creating an instance of the &lt;i&gt;MobileServiceClient&lt;/i&gt; object in the AMS SDK:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; mobileService = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Microsoft.WindowsAzure.MobileServices.MobileServiceClient(&lt;br /&gt;    &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;https://{mobile-service-url}.azure-mobile.net/&amp;quot;&lt;/span&gt;,&lt;br /&gt;    &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;{mobile-service-key}&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C#:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; Microsoft.WindowsAzure.MobileServices;&lt;br /&gt;&lt;br /&gt;MobileServiceClient MobileService = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MobileServiceClient(&lt;br /&gt;    &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;https://{mobile-service-url}.azure-mobile.net/&amp;quot;&lt;/span&gt;,&lt;br /&gt;    &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;{mobile-service-key}&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C++&lt;/strong&gt; (taken from &lt;a href="http://code.msdn.microsoft.com/windowsapps/C-Windows-Store-apps-and-ab1ea114"&gt;an additional sample&lt;/a&gt;):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;namespace&lt;/span&gt; Microsoft::WindowsAzure::MobileServices;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;auto&lt;/span&gt; MobileService = ref &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MobileServiceClient(&lt;br /&gt;    ref &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(L&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot; https://{mobile-service-url}.azure-mobile.net/&amp;quot;&lt;/span&gt;), &lt;br /&gt;    ref &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; String(L&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;{mobile-service-key}&amp;quot;&lt;/span&gt;));&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;This class encapsulates all the HTTP communication with the service, relieving you from all that low-level plumbing that you probably don’t want to think about.&lt;/p&gt;

&lt;p&gt;To authenticate with a particular OAuth provider, use the &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554236.aspx"&gt;&lt;i&gt;login&lt;/i&gt;&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj553650.aspx"&gt;&lt;i&gt;LoginAsync&lt;/i&gt;&lt;/a&gt; method, the result of which is a &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554220.aspx"&gt;&lt;i&gt;User&lt;/i&gt;&lt;/a&gt; object that provides that information to the app. (Once authenticated, &lt;i&gt;CurrentUser&lt;/i&gt; property of the client object will also contain the user id.) When you authenticate the mobile service directly like this, the service will have access to the user id and there’s no need for the client to send it explicitly:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;mobileService.login(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;facebook&amp;quot;&lt;/span&gt;).done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* ... */&lt;/span&gt; });&lt;br /&gt;mobileService.login(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;twitter&amp;quot;&lt;/span&gt;).done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* ... */&lt;/span&gt; });&lt;br /&gt;mobileService.login(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;google&amp;quot;&lt;/span&gt;).done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* ... */&lt;/span&gt; });&lt;br /&gt;mobileService.login(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;microsoftaccount&amp;quot;&lt;/span&gt;).done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* ... */&lt;/span&gt; });&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C#:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;MobileServiceUser user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.Facebook);&lt;br /&gt;MobileServiceUser user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.Twitter);&lt;br /&gt;MobileServiceUser user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.Google);&lt;br /&gt;MobileServiceUser user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C++:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;task&amp;lt;MobileServiceUser^&amp;gt; (MobileService-&amp;gt;LoginAsync(MobileServiceAuthenticationProvider::Facebook))&lt;br /&gt;    .then([&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;](MobileServiceUser^ user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* */&lt;/span&gt; } );&lt;br /&gt;task&amp;lt;MobileServiceUser^&amp;gt; (MobileService-&amp;gt;LoginAsync(MobileServiceAuthenticationProvider::Twitter))&lt;br /&gt;    .then([&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;](MobileServiceUser^ user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* */&lt;/span&gt; } );&lt;br /&gt;task&amp;lt;MobileServiceUser^&amp;gt; (MobileService-&amp;gt;LoginAsync(MobileServiceAuthenticationProvider::Google))&lt;br /&gt;    .then([&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;](MobileServiceUser^ user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* */&lt;/span&gt; } );&lt;br /&gt;task&amp;lt;MobileServiceUser^&amp;gt; (MobileService-&amp;gt;LoginAsync(MobileServiceAuthenticationProvider::MicrosoftAccount))&lt;br /&gt;    .then([&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;](MobileServiceUser^ user) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* */&lt;/span&gt; } );&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sending a channel URI to the service is again a simple matter of storing a record in the service’s database, and the client object makes the HTTP requests. To do this, just request the database object and insert the record as shown in the examples below from the push notification tutorial sample linked earlier. In each code snippet, assume that &lt;i&gt;ch &lt;/i&gt;contains the &lt;i&gt;PushNotificationChannel&lt;/i&gt; object from the WinRT APIs. You can also include any other properties in the &lt;i&gt;channel &lt;/i&gt;object that’s built up, such as a secondary tile id or other data that identifies the channel’s purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; channelTable = MobileServicesSample.mobileService.getTable(&lt;span style="color: rgb(0, 96, 128);"&gt;'Channels'&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; channel = {&lt;br /&gt;    uri: ch.uri, &lt;br /&gt;    expirationTime: ch.expirationTime.&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;channelTable.insert(channel).done(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; (item) {&lt;br /&gt;&lt;br /&gt;    },&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; () {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Error on the insertion.&lt;/span&gt;&lt;br /&gt;    });&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C#: &lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;var channel = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Channel { Uri = ch.Uri, ExpirationTime = ch.ExpirationTime };&lt;br /&gt;var channelTable = privateClient.GetTable&amp;lt;Channel&amp;gt;();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (ApplicationData.Current.LocalSettings.Values[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;ChannelId&amp;quot;&lt;/span&gt;] == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Use try/catch block here to handle exceptions&lt;/span&gt;&lt;br /&gt;    await channelTable.InsertAsync(channel);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;C++:&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;auto&lt;/span&gt; channel = ref &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonObject();&lt;br /&gt;channel-&amp;gt;Insert(L&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Uri&amp;quot;&lt;/span&gt;, JsonValue::CreateStringValue(ch-&amp;gt;Uri));&lt;br /&gt;channel-&amp;gt;Insert(L&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;ExpirationTime&amp;quot;&lt;/span&gt;, JsonValue::CreateBooleanValue(ch-&amp;gt;ExpirationTime));&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;auto&lt;/span&gt; table = MobileService-&amp;gt;GetTable(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Channel&amp;quot;&lt;/span&gt;);&lt;br /&gt;task&amp;lt;IJsonValue^&amp;gt; (table-&amp;gt;InsertAsync(channel))&lt;br /&gt;    .then([&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;, item](IJsonValue^ V) { &lt;span style="color: rgb(0, 128, 0);"&gt;/* ... */&lt;/span&gt; });&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that once the channel record has been inserted, any changes or additions that the service might have made to that record will be reflected in the client.&lt;/p&gt;

&lt;p&gt;In addition, if you misspell the name of the database in the &lt;i&gt;GetTable&lt;/i&gt;/&lt;i&gt;getTable&lt;/i&gt; call, you won’t see any exceptions until you try to insert a record. This can be a hard bug to track down, so if you’re convinced everything should be working, but it isn’t, check that database name.&lt;/p&gt;

&lt;p&gt;Now again, these insertions on the client side are translated into HTTP requests to the service, but even on the service side this is also hidden from you. Instead of receiving and processing the requests, you attach custom scripts to each database operation (insert, read, update, and delete).&lt;/p&gt;

&lt;p&gt;These scripts are written as JavaScript functions using the same intrinsic objects and methods that are available in Node.js (all of which has nothing whatsoever to do with any client-side JavaScript in the app). Each function receives appropriate parameters: &lt;i&gt;insert&lt;/i&gt; and &lt;i&gt;update&lt;/i&gt; receive the new record, &lt;i&gt;delete&lt;/i&gt; receives the id of the item, and &lt;i&gt;read&lt;/i&gt; receives a query. All the functions also receive a &lt;i&gt;user&lt;/i&gt; object, if the app authenticated the user with the mobile service, and a &lt;i&gt;request &lt;/i&gt;object that lets you execute the operation and generate what becomes the HTTP response.&lt;/p&gt;

&lt;p&gt;The simplest (and default) &lt;i&gt;insert&lt;/i&gt; script, just executes the request and inserts the record, &lt;i&gt;item&lt;/i&gt;, as-is:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(204, 102, 51);"&gt;function&lt;/span&gt; insert(item, user, request) {&lt;br /&gt;    request.execute();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you want to attach a timestamp and the user id to the record, it’s as easy as adding those properties to the &lt;i&gt;item &lt;/i&gt;parameter prior to executing the request:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(204, 102, 51);"&gt;function&lt;/span&gt; insert(item, user, request) {&lt;br /&gt;    item.user = user.userId;&lt;br /&gt;    item.createdAt = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Date();&lt;br /&gt;    request.execute();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that the changes made to &lt;i&gt;item &lt;/i&gt;in these scripts before insertion into the database are automatically propagated back to the client. In the code above, the &lt;i&gt;channel&lt;/i&gt; object in the client would contain &lt;i&gt;user &lt;/i&gt;and &lt;i&gt;createdAt &lt;/i&gt;properties once the insertion succeeds. Very convenient!&lt;/p&gt;

&lt;p&gt;The service scripts can also perform additional actions after &lt;i&gt;request.execute&lt;/i&gt;, especially in response to success or failure, but I’ll leave such details to the &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj591477.aspx"&gt;Server script example how tos documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To return now to push notifications, saving channel URIs into a table is just one part of the equation, and the service may or may not send notifications in response to this particular event. It’s more likely that the service will have other tables with additional information, where operations performed on those tables trigger notifications to some subset of channel URIs. We’ll discuss a few examples in the next section. Whatever the case may be, you send a push notification from a script using the &lt;a href="https://github.com/tjanczuk/wns/blob/master/README.md"&gt;&lt;i&gt;push.wns&lt;/i&gt;&lt;/a&gt;&lt;i&gt; &lt;/i&gt;object. This again has many methods to send specific types of updates (including raw), where tiles, toasts, and badges work directly through names methods that match the available templates. For example:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;push.wns.sendTileSquarePeekImageAndText02(channel.uri, {&lt;br /&gt;    image1src: baseImageUrl + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;image1.png&amp;quot;&lt;/span&gt;,&lt;br /&gt;    text1: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Notification Received&amp;quot;&lt;/span&gt;,&lt;br /&gt;    text2: item.text&lt;br /&gt;}, {&lt;br /&gt;    success: &lt;span style="color: rgb(204, 102, 51);"&gt;function&lt;/span&gt; (pushResponse) {&lt;br /&gt;        console.log(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Sent Tile Square:&amp;quot;&lt;/span&gt;, pushResponse);&lt;br /&gt;    },&lt;br /&gt;    error: &lt;span style="color: rgb(204, 102, 51);"&gt;function&lt;/span&gt; (err) {&lt;br /&gt;        console.log(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Error sending tile:&amp;quot;&lt;/span&gt;, err);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;push.wns.sendToastImageAndText02(channel.uri, {&lt;br /&gt;    image1src: baseImageUrl + &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;image2.png&amp;quot;&lt;/span&gt;,&lt;br /&gt;    text1: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Notification Received&amp;quot;&lt;/span&gt;,&lt;br /&gt;    text2: item.text&lt;br /&gt;}, {&lt;br /&gt;    success: &lt;span style="color: rgb(204, 102, 51);"&gt;function&lt;/span&gt; (pushResponse) {&lt;br /&gt;        console.log(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Sent Toast:&amp;quot;&lt;/span&gt;, pushResponse);&lt;br /&gt;    }&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;push.wns.sendBadge(channel.uri, {&lt;br /&gt;    value: value,&lt;br /&gt;    text1: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Notification Received&amp;quot;&lt;/span&gt;&lt;br /&gt;}, {&lt;br /&gt;    success: &lt;span style="color: rgb(204, 102, 51);"&gt;function&lt;/span&gt; (pushResponse) {&lt;br /&gt;        console.log(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Sent Badge:&amp;quot;&lt;/span&gt;, pushResponse);&lt;br /&gt;    }&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Again, the &lt;i&gt;console.log &lt;/i&gt;function creates an entry in the logs that you can view on the Azure Mobile Services portal, and you’ll typically want to include log calls in error handlers as shown with the tile notification above.&lt;/p&gt;

&lt;p&gt;You might have noticed that the &lt;i&gt;send*&lt;/i&gt; methods are each tied to a specific template, and for tiles it means that wide and square payloads must be sent separately as two notifications. Remember that you almost always want to send both sizes together because the user controls how that tile appears on their Start screen. With the template specific &lt;i&gt;send &lt;/i&gt;functions of &lt;i&gt;push.wns&lt;/i&gt;, then, it means making two sequential calls each of which generate a separate push notification.&lt;/p&gt;

&lt;p&gt;To combine multiple updates, which includes sending multiple tile updates with different tags at one time or sending multiple toasts, use the &lt;i&gt;push.wns.sendTile&lt;/i&gt; and &lt;i&gt;push.wns.sendToast&lt;/i&gt; methods. For example:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;var channel = &lt;span style="color: rgb(0, 96, 128);"&gt;'{channel_url}'&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;push.wns.sendTile(channel,&lt;br /&gt;    { type: &lt;span style="color: rgb(0, 96, 128);"&gt;'TileSquareText04'&lt;/span&gt;, text1: &lt;span style="color: rgb(0, 96, 128);"&gt;'Hello'&lt;/span&gt; },&lt;br /&gt;    { type: &lt;span style="color: rgb(0, 96, 128);"&gt;'TileWideText09'&lt;/span&gt;, text1: &lt;span style="color: rgb(0, 96, 128);"&gt;'Hello'&lt;/span&gt;, text2: &lt;span style="color: rgb(0, 96, 128);"&gt;'How are you?'&lt;/span&gt; },&lt;br /&gt;    { client_id: &lt;span style="color: rgb(0, 96, 128);"&gt;'{your Package Security Identifier}'&lt;/span&gt;, client_secret: &lt;span style="color: rgb(0, 96, 128);"&gt;'{your Client Secret}'&lt;/span&gt; },&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(204, 102, 51);"&gt;function&lt;/span&gt; (error, result) {&lt;br /&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// ...&lt;/span&gt;&lt;br /&gt;    });&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;On an even lower level, &lt;i&gt;push.wns.send&lt;/i&gt; lets you be very exact with the notification contents; &lt;i&gt;push.wns.sendRaw&lt;/i&gt; is also there for raw notifications. For all the details, refer again to the &lt;a href="https://github.com/tjanczuk/wns/blob/master/README.md" target="_blank"&gt;push.wns&lt;/a&gt;&lt;i&gt;&lt;/i&gt; object documentation.&lt;/p&gt;

&lt;h2&gt;Real-world scenarios with Windows Azure Mobile Services&lt;/h2&gt;

&lt;p&gt;The sample app in the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Tile-Toast-and-Badge-Push-90ee6ff1" target="_blank"&gt;Tile, Toast, and Badge Push Notifications using Windows Azure Mobile Services&lt;/a&gt; shows how to send push notifications in response to a new message being inserted into a database table. However, this means that the app ends up sending a push notification to itself, which it wouldn’t typically need to do (except perhaps to send notifications to the same app on the user’s other devices).&lt;/p&gt;

&lt;p&gt;What’s more likely to happen is that the service will send push notifications in response to events that occur outside the app/tile that ultimately receives those notifications. Consider a few scenarios:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Using Social Networks&lt;/b&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Apps can employ a user’s social network to implement features like issuing challenges to one’s friends. For example, when one user sets a new high score in a game, you might want to issue challenges via tile updates or toasts to the user’s friends who also have that game installed. The same thing can happen in fitness apps where you might be posting a new best time for a certain kind of activity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;To do this, the app can insert a new record into an appropriate mobile service table (Scores, BestTimes, etc.). Within the insert script, the service queries its database for appropriate friends of the current user, then sends notifications to those channel URIs. Additional query criteria describe the exact aspect of a game, the particular kind of exercise (for secondary tiles), and so on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Weather updates and alerts&lt;/b&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Weather apps typically allow you to assign a location to the app’s primary tile and to create secondary tiles for additional locations. The important information with each tile is the latitude and longitude of the location, which the app sends to the service along with each channel URI (by inserting into a table). To trigger an update to that channel, the service might have another process (such as a scheduled job described below) that periodically queries a central weather service for updates and alerts, and then processes those responses and inserts the appropriate messages into an alerts table in the mobile service. The insert script then retrieves appropriate channel URIs and sends the updates. Alternately, if a weather service itself allows you to register for alerts or periodic updates, another page in the service would receive those requests (HTTP PUTs, most likely), process them, and invoke the mobile service to insert a record, thus triggering an update.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Messaging&lt;/b&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Handling instant messaging happens very much in the same way as receiving weather updates. Again, another process monitors the receipt of new messages, such as one that checks the incoming messages periodically, or registers with the message source for alerts when new messages arrive. In either case, the arrival of a new message triggers push notifications to the appropriate channels. In this case the channel URIs is associated with a user’s tile for a particular kind of messaging. You’d likely use raw notifications in this case, as it’s similar to the email scenario described at the beginning of this post.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In all of these scenarios, note that it’s not actually necessary to insert anything into a database table at all. If you don’t call &lt;i&gt;request.execute&lt;/i&gt; in the insertion script, nothing ends up in the database, yet you can still perform other tasks within that script such as sending notifications. In other words, there’s no need to fill up a database with records that you aren’t going to use later on, especially because storing data incurs costs.&lt;/p&gt;

&lt;p&gt;Note too that Azure Mobile Services has a facility for scheduling jobs, which you can read about on &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/schedule-backend-tasks/" target="_blank"&gt;Schedule recurring jobs in Mobile Services&lt;/a&gt;. Such jobs could routinely retrieve data from other services, process it, and insert records into the service’s database, again triggering push notifications. Likewise, as we pointed out in Part 2 of this series, other webpages and mobile apps can also make changes to that database and trigger push notifications. The database scripts in the mobile service will run in all of these cases.&lt;/p&gt;

&lt;h2&gt;In closing&lt;/h2&gt;

&lt;p&gt;To wrap up this series, then, we’ve explored the whole scope of what “alive with activity” means-for users, for developers, for apps, and for services. We’ve seen the capabilities of tile, badge, and toast updates, how to set up periodic notifications, how to use background tasks as part of this process, and the structure of services to handle periodic and push notifications. And clearly, Windows Azure Mobile Services provides a much higher-level view of the whole process of working with push notifications. It can certainly help you be much more productive—and save you many headaches, most likely!—than writing new services from scratch.&lt;/p&gt;

&lt;p&gt;Kraig Brockschmidt
  &lt;br /&gt;Program Manager, Windows Ecosystem Team 

  &lt;br /&gt;Author, &lt;a href="http://blogs.msdn.com/b/microsoft_press/archive/2012/10/29/free-ebook-programming-windows-8-apps-with-html-css-and-javascript.aspx"&gt;&lt;i&gt;Programming Windows 8 Apps in HTML, CSS, and JavaScript&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10402141" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/mobile+services/">mobile services</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Azure/">Azure</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/push+notifications/">push notifications</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+Azure+Mobile+Services/">Windows Azure Mobile Services</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/WNS/">WNS</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/tile+updates/">tile updates</category></item><item><title>Alive with activity, part 2: Writing and debugging services for live tiles</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2013/03/04/alive-with-activity-part-2-writing-and-debugging-services-for-live-tiles.aspx</link><pubDate>Mon, 04 Mar 2013 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10397967</guid><dc:creator>Windows 8 Team</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/windowsappdev/rsscomments.aspx?WeblogPostID=10397967</wfw:commentRss><comments>http://blogs.msdn.com/b/windowsappdev/archive/2013/03/04/alive-with-activity-part-2-writing-and-debugging-services-for-live-tiles.aspx#comments</comments><description>&lt;p&gt;In &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2013/02/21/alive-with-activity-part-1-working-with-tiles-badges-and-toasts.aspx" target="_blank"&gt;Part 1 of this series&lt;/a&gt; we explored the nature of tile updates, badge updates, and toast notifications that bring a sense of “aliveness” to the overall user experience of Windows 8. In particular, we saw how these notifications are composed with XML payloads that are then issued locally, from a running app or a background task, or can be supplied upon request by an online service.&lt;/p&gt;  &lt;p&gt;Generating an XML payload and issuing it from a running app is something you can easily develop and debug within an app using Visual Studio Ultimate 2012 or Visual Studio Express 2012 for Windows 8. The &lt;a href="http://code.msdn.microsoft.com/windowsapps/App-tiles-and-badges-sample-5fc49148" target="_blank"&gt;App tiles and badges sample&lt;/a&gt;, &lt;a href="http://code.msdn.microsoft.com/windowsapps/Secondary-Tiles-Sample-edf2a178" target="_blank"&gt;Secondary tiles sample&lt;/a&gt;, and the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Scheduled-notifications-da477093" target="_blank"&gt;Scheduled notifications sample&lt;/a&gt;, give you everything you need here.&lt;/p&gt;  &lt;p&gt;What takes a little more effort is developing and debugging a web service to support periodic updates as well as push notifications. The client side of these stories is well-demonstrated in the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Push-and-periodic-de225603" target="_blank"&gt;Push and periodic notifications client-side sample&lt;/a&gt;, but in order to make use of that sample at all you need some services to work with! In this post, we’ll specifically explore how to develop services that support periodic notifications for tile and badge updates, with a focus on using Visual Studio tools and the localhost to debug your services before deploying them to a production environment. We’ll also begin to explore how you can use Windows Azure Mobile Services for this purpose, which are also very helpful in supporting push notifications as we’ll see in Part 3.&lt;/p&gt;  &lt;h2&gt;The basic nature of services&lt;/h2&gt;  &lt;p&gt;What does a service that supports periodic tile and badge updates actually do? Let’s begin by reviewing what we mean by a “service,” because that word is often rather intimidating for developers who have primarily been focused on client apps.&lt;/p&gt;  &lt;p&gt;In the simplest terms, a service is some piece of code sitting on some web server that runs &lt;i&gt;on that server &lt;/i&gt;whenever an HTTP request is made to it. HTML pages (.htm or .html) are not like this: as there’s no server-side code involved, the server simply returns that page’s text and all processing is done on the client (including running any client-side script contained in that page). However, if you have URIs to pages that end with php, asp, aspx, cgi, cshtml, or any number of other server-side extensions, you’re effectively talking to a “service” in this most general sense.&lt;/p&gt;  &lt;p&gt;A service is responsible to receive a client HTTP request, process whatever arguments might be included with the URI, and return an appropriate text response. For &lt;i&gt;web pages&lt;/i&gt; written with technologies like PHP or ASP.NET, the response should be in the form of HTML. Services that implement web APIs, such as those of Facebook and Twitter (and thousands of others!), typically accept any number of parameters in URI query strings (or in the request header), and return either XML or JSON data in response. (And just to note, we’re talking here of services built on &lt;a href="http://en.wikipedia.org/wiki/Representational_state_transfer" target="_blank"&gt;representational state transfer&lt;/a&gt;, or REST, rather than those build on other protocols like &lt;a href="http://en.wikipedia.org/wiki/SOAP" target="_blank"&gt;SOAP&lt;/a&gt;, as REST the most common among services today.)&lt;/p&gt;  &lt;p&gt;Thus a service that provides periodic tile and/or badge updates is simply one that exists at whatever URI an app gives to Windows for this purpose, and which responds to HTTP requests with an appropriate XML payload. That payload contains elements that correspond to any supported template, where images are referenced with other URIs (inline encoding is not supported). The specific information included in the payload can also come from any source, as we’ll discuss in a bit.&lt;/p&gt;  &lt;p&gt;Regardless of such details, however, all such services share a similar structure that receives and processes the request, and constructs the XML response. Let’s now look at how to create that basic structure.&lt;/p&gt;  &lt;h2&gt;Writing services&lt;/h2&gt;  &lt;p&gt;To write and debug services you can use whatever tools you want as long as they support your chosen server-side language. Here we’ll focus on Visual Studio, specifically Visual Studio Ultimate 2012 and &lt;a href="http://msdn.microsoft.com/en-us/subscriptions/dd537667(v=vs.110).aspx" target="_blank"&gt;Visual Studio Express 2012 for Web&lt;/a&gt;&lt;b&gt;&lt;/b&gt;, the latter of which is available for free alongside its Windows partner that you already know. To install it, run the &lt;a href="http://www.microsoft.com/web/downloads/platform.aspx" target="_blank"&gt;Web Platform Installer&lt;/a&gt; through which you can also install a variety of other related technologies such as PHP and WebMatrix. This allows you to create services in a variety of languages.&lt;/p&gt;  &lt;p&gt;As a very simple example, the following code comprises a complete PHP service that responds with a badge update XML payload in which the badge value is set to the current day of the month (according to the server, mind you!). It comes from the HelloTiles sample site that’s included in Chapter 13 of my free ebook, &lt;a href="http://blogs.msdn.com/b/microsoft_press/archive/2012/10/29/free-ebook-programming-windows-8-apps-with-html-css-and-javascript.aspx" target="_blank"&gt;Programming Windows 8 Apps with HTML, CSS, and JavaScript:&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;div id="codeSnippetWrapper"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;php&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;echo&lt;/span&gt; '&amp;amp;&lt;span style="color: rgb(255, 0, 0);"&gt;lt&lt;/span&gt;;?&lt;span style="color: rgb(255, 0, 0);"&gt;xml&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;version&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;encoding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;';&lt;br /&gt;    echo &amp;quot;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;badge&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;='&amp;quot;.date(&amp;quot;j&amp;quot;).&amp;quot;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&amp;quot;;&lt;br /&gt;?&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can try this service directly. Click this link on the Windows Azure site I set up for this purpose--&lt;a href="http://programmingwin8-js-ch13-hellotiles.azurewebsites.net/dayofmonhservice.php"&gt;http://programmingwin8-js-ch13-hellotiles.azurewebsites.net/dayofmonhservice.php&lt;/a&gt;--and you’ll see that the XML that comes back is something like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xml&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;version&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;encoding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;UTF-8&amp;quot;&lt;/span&gt;?&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;badge&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;24&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Try this same URI in the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Push-and-periodic-de225603" target="_blank"&gt;Push and periodic notifications client-side sample&lt;/a&gt;, scenario 5, “Polling for badge updates.” When you first run the app (within Visual Studio Express for Windows), its tile appears on the start screen as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/5008.push_5F00_js_5F00_1_5F00_5F4DC8FF.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Polling for badge updates tile" border="0" alt="Polling for badge updates tile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/2845.push_5F00_js_5F00_1_5F00_thumb_5F00_061BDF40.png" width="400" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now enter the URI above into the text box in scenario 5, press the Start periodic updates button, and, assuming you have network connectivity, you’ll soon see a numerical badge appear on the sample’s tile:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0702.push_5F00_js_5F00_2_5F00_6600D282.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Tile with numeric badge" border="0" alt="Tile with numeric badge" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7658.push_5F00_js_5F00_2_5F00_thumb_5F00_45E5C5C5.png" width="400" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that Windows tries to poll for an update as soon as the app starts periodic updates, then continues to poll at the specified interval thereafter.&lt;/p&gt;

&lt;p&gt;For a fuller PHP example, see &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/04/18/creating-a-great-tile-experience-part-2.aspx" target="_blank"&gt;Creating a great tile experience, part 2,&lt;/a&gt; which shows more customization of a tile update. In that example, the hypothetical &lt;i&gt;get_trucks_from_database&lt;/i&gt; function queries a database using a zip code that’s included in the URI’s query string parameters, then builds the XML response with the results of that query.&lt;/p&gt;

&lt;p&gt;There’s much more the service could do along these lines. For example:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;With the day-of-month PHP service above, the app could indicate its local time zone in the query string to get a more accurate date, because the server can easily be located in another time zone.&lt;/li&gt;

  &lt;li&gt;A weather service could use latitude and longitude values in the URI to retrieve current conditions for that location.&lt;/li&gt;

  &lt;li&gt;The service could generate images on the fly and store them on a web server, then insert appropriate URIs into the XML payload.&lt;/li&gt;

  &lt;li&gt;The service would send its own requests to other services to obtain additional data, customized with the query string parameters (more on this later).&lt;/li&gt;

  &lt;li&gt;If an app enables the queue for tile updates (see the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.tileupdater.enablenotificationqueue.aspx" target="_blank"&gt;EnableNotificationQueue&lt;/a&gt;&lt;i&gt;&lt;/i&gt; method), it can specify up to five separate URIs to poll for periodic updates, as demonstrated in scenario 4 of the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Push-and-periodic-de225603" target="_blank"&gt;Push and periodic notifications client-side sample&lt;/a&gt;. The tile update queue will be populated with an update from each URI. Each one of those URIs, of course, can have its own query string for further customization such that the same service could accommodate all the requests itself.&lt;/li&gt;

  &lt;li&gt;An app could include a user id in the query string such that the service could query its data stores for the user’s workout history, their high scores in a game, news items from the feeds they’re registered, and so forth. In such cases, a user id could be personally-identifiable information (PII), so the app must respect privacy concerns. This means that the app should either encrypt the username in the query string or use https:// URIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: Windows doesn’t provide a means within the periodic update mechanism to authenticate the user with the service. That level of support can only be accomplished with push notifications (or in enterprise scenarios with the Enterprise Authentication capability declared in the manifest).&lt;/p&gt;

&lt;p&gt;Services can be written with other technologies, of course. ASP.NET is a good choice because you can then employ the same &lt;a href="http://msdn.microsoft.com/library/windows/apps/hh969156.aspx" target="_blank"&gt;Notifications Extensions Library&lt;/a&gt; (written in C#) that you can use in an app to easily generate well-structured XML payloads.&lt;/p&gt;

&lt;p&gt;To walk through a quick example, consider the very basic WebMatrix service I created for the HelloTiles sample service in Chapter 13 of my book (&lt;a href="http://go.microsoft.com/FWLink/?Linkid=270057" target="_blank"&gt;see the companion content&lt;/a&gt;). This particular service just returns a fixed XML payload (with bindings for both square and wide tiles) and is structurally similar to the first ASP.NET example given in &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/04/18/creating-a-great-tile-experience-part-2.aspx" target="_blank"&gt;Creating a great tile experience, part 2&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;@{&lt;br /&gt;  //&lt;br /&gt;  // This is where any other code would be placed to acquire the dynamic content&lt;br /&gt;  // needed for the tile update. In this case we'll just return static XML to show&lt;br /&gt;  // the structure of the service itself.&lt;br /&gt;  // &lt;br /&gt;  var weekDay = DateTime.Now.DayOfWeek;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xml&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;version&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;encoding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tile&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;visual&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;lang&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;en-US&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;template&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;TileSquarePeekImageAndText02&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;branding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;image&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;src&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://www.kraigbrockschmidt.com/images/Liam07.png&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;Liam--&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;Giddy on the day he learned to sit up!&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;template&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;TileWideSmallImageAndText04&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;branding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;image&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;src&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://www.kraigbrockschmidt.com/images/Liam08.png&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;This is Liam&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;Exploring the great outdoors!&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;text&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;visual&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tile&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;This particular service is deployed to &lt;a href="http://programmingwin8-js-ch13-hellotiles.azurewebsites.net/Default.cshtml" target="_blank"&gt;http://programmingwin8-js-ch13-hellotiles.azurewebsites.net/Default.cshtml&lt;/a&gt; if you want to give it a try in scenario 4 of the Push and periodic notifications client-side sample. In doing so, after a few seconds, you’ll see the following tile updates (wide on the left, and the two parts of the square peek tile on the right):&lt;/p&gt;

&lt;div align="center"&gt;
  &lt;table class="b8table" border="0" cellspacing="0" cellpadding="3" align="center"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="312"&gt;
          &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8228.liam_5F00_1_5F00_25CAB908.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="liam_1" border="0" alt="liam_1" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/5670.liam_5F00_1_5F00_thumb_5F00_05AFAC4B.png" width="350" height="169" /&gt;&lt;/a&gt;&lt;/p&gt;
        &lt;/td&gt;

        &lt;td valign="top" width="617"&gt;
          &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0207.liam_5F00_2_5F00_457992D0.png"&gt;&lt;img style="border: 0px currentcolor; display: inline; background-image: none;" title="liam_2" border="0" alt="liam_2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0211.liam_5F00_2_5F00_thumb_5F00_106D03A0.png" width="175" height="175" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8625.liam_5F00_tile_5F00_373B19E0.png"&gt;&lt;img style="border: 0px currentcolor; display: inline; background-image: none;" title="liam_tile" border="0" alt="liam_tile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/6562.liam_5F00_tile_5F00_thumb_5F00_2C118F96.png" width="175" height="176" /&gt;&lt;/a&gt;&lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;Let’s now write the same thing using the Notification Extensions Library. The first thing you’ll need to do is build a version of the library for your website as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Go to the &lt;a href="http://code.msdn.microsoft.com/windowsapps/App-tiles-and-badges-sample-5fc49148" target="_blank"&gt;App tiles and badges sample&lt;/a&gt; and copy the Notifications Extensions folder from that project into a folder of your own. (You can also install the library from Visual Studio directly by right-clicking on a project, selecting Manage NuGet Packages… and searching for &lt;i&gt;NotificationsExtensions.WinRT&lt;/i&gt;. However, this is meant to bring the library into an existing app project whereas we need to build a standalone DLL here.)&lt;/li&gt;

  &lt;li&gt;In Visual Studio Express for Windows, open the NotificationsExtensions.csproj file.&lt;/li&gt;

  &lt;li&gt;In Solution Explorer, right click the NotificationExtensions project, select Properties, and make the following changes:&lt;/li&gt;

  &lt;ol&gt;
    &lt;li&gt;In the Application settings, change the Output type to &lt;i&gt;Class Library &lt;/i&gt;(a .dll). This is necessary to use the library with an ASP.NET site.&lt;/li&gt;

    &lt;li&gt;In the Build settings, change the Configuration to &lt;i&gt;All Configurations&lt;/i&gt;, change the conditional compilation symbols to read &lt;i&gt;NETFX_CORE; WINRT_NOT_PRESENT&lt;/i&gt;, and make sure XML documentation file is checked near the bottom of the page. The &lt;i&gt;WINRT_NOT_PRESENT&lt;/i&gt; flag enables the library to compile without WinRT.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;li&gt;Select a Debug or Release target, then right-click the Notifications Extensions project, and select &lt;b&gt;Build&lt;/b&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This should generate a DLL and associated files in that project folder. Now we need to pull it into a website project.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;In Visual Studio Express for Web, right-click your website project and select &lt;b&gt;Add &lt;/b&gt;&amp;gt; &lt;b&gt;Add ASP.NET folder &lt;/b&gt;&amp;gt; &lt;b&gt;Bin&lt;/b&gt; if your site doesn’t have a Bin folder already.&lt;/li&gt;

  &lt;li&gt;Right-click that Bin folder and select &lt;b&gt;Add Reference&lt;/b&gt;…. In &lt;b&gt;Add Reference&lt;/b&gt;, go to the &lt;b&gt;bin\Debug&lt;/b&gt; or &lt;b&gt;bin\Release&lt;/b&gt; folder of the Notifications Extensions project and select the DLL found there.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you’re using Visual Studio Ultimate, you can add the Notification Extensions project to your website solution, if desired, as the tool can handle both project types. Just be sure you don’t deploy the source code for that project to your web server!&lt;/p&gt;

&lt;p&gt;Also note that if you build your site to run it locally in a browser (as we’ll see in the Debugging section below), you might get an error about adding a reference to &lt;i&gt;System.Runtime&lt;/i&gt;. To correct this, open the web.config file and change the &lt;i&gt;compilation &lt;/i&gt;element to read as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;compilation&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;debug&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;targetFramework&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;4.0&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;assemblies&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;add&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;assembly&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;assemblies&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;compilation&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;With all this in place, here’s a page (called DefaultNE.aspx) that produces the same output as the earlier hard-coded example:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xml&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;version&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;encoding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: rgb(255, 255, 0);"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;script&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt;&amp;#160; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; GenerateTileXML()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Construct the square template&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         NotificationsExtensions.TileContent.ITileSquarePeekImageAndText02 squareTile = &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;             NotificationsExtensions.TileContent.TileContentFactory.CreateTileSquarePeekImageAndText02();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         squareTile.Branding = NotificationsExtensions.TileContent.TileBranding.None;        &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         squareTile.Image.Src = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://www.kraigbrockschmidt.com/images/Liam07.png&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         squareTile.TextHeading.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Liam--&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         squareTile.TextBodyWrap.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Giddy on the day he learned to sit up!&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Construct the wide template&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         NotificationsExtensions.TileContent.ITileWideSmallImageAndText04 wideTile =&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;             NotificationsExtensions.TileContent.TileContentFactory.CreateTileWideSmallImageAndText04();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         wideTile.Branding = NotificationsExtensions.TileContent.TileBranding.None;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         wideTile.Image.Src = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://www.kraigbrockschmidt.com/images/Liam08.png&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         wideTile.TextHeading.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;This is Liam&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         wideTile.TextBodyWrap.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Exploring the great outdoors!&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;                 &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Attach the square template to the notification&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         wideTile.SquareContent = squareTile;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         wideTile.Lang = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;en-US&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// The wideTile object is an XMLDOM object, suitable for issuing tile updates&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// directly. In this case we just want the XML text.&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; wideTile.ToString();        &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;script&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: rgb(255, 255, 0);"&gt;&amp;lt;%&lt;/span&gt;&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt;  = GenerateTileXML() &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;span style="background-color: rgb(255, 255, 0);"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can visit this service at &lt;a href="http://programmingwin8-js-ch13-hellotiles.azurewebsites.net/DefaultNE.aspx" target="_blank"&gt;http://programmingwin8-js-ch13-hellotiles.azurewebsites.net/DefaultNE.aspx&lt;/a&gt;, from which you’ll get essentially the same XML back as before, with very minor differences. Pasting the URI into scenario 4 of the Push and periodic notifications client-side sample will also generate the same tile updates as before.&lt;/p&gt;

&lt;h2&gt;Debugging services&lt;/h2&gt;

&lt;p&gt;Generating a successful tile or badge update assumes, of course, that the XML in the service’s response is properly formed: Windows rejects any XML that isn’t. This is a good reason to use the Notifications Extensions Library as it greatly reduces the errors you might otherwise make in the process.&lt;/p&gt;

&lt;p&gt;But what if your service isn’t working well at all? How you can diagnose and debug how it’s handling requests and generating its response?&lt;/p&gt;

&lt;p&gt;In fact, when I first tried the ASP.NET service code above, the updates didn’t appear because there was a leading newline at the top of the XML response. This is specifically why the &lt;i&gt;&amp;lt;?xml ?&amp;gt;&lt;/i&gt; header appears as the first line in the file rather than after the &lt;i&gt;&amp;lt;%@ Page %&amp;gt;&lt;/i&gt; directive, and why there aren’t any extra line feeds.&lt;/p&gt;

&lt;p&gt;Clearly, there are many reasons why you’ll want to be able to step through your service code and debug it line by line, especially if you’re querying a database and processing those query results.&lt;/p&gt;

&lt;p&gt;The trick to doing this is to use the localhost on your development machine, which allows you to run and debug your service locally at the same time you’re running client test code such as the SDK samples.&lt;/p&gt;

&lt;p&gt;Having a localhost means you’re running a local web server like Internet Information Services or Apache. To turn on IIS in Windows (its built-in), go to &lt;b&gt;Control Panel&lt;/b&gt; &amp;gt; &lt;b&gt;Turn Windows features on or off&lt;/b&gt;. Check the Internet Information Services box at the top level, as shown below, to install the core features:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7142.windows_2D00_features_2D00_window_5F00_0BF682D9.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Windows Features dialog box with Internet Information Services checked" border="0" alt="Windows Features dialog box with Internet Information Services checked" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1778.windows_2D00_features_2D00_window_5F00_thumb_5F00_56E9F3A8.png" width="500" height="438" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After IIS is installed, the local site addressed by &lt;i&gt;http://localhost/&lt;/i&gt; is found in the folder &lt;i&gt;c:\inetpub\wwwroot&lt;/i&gt;. That’s where you drop something like the PHP page described in the last section so that you can use a URI like &lt;i&gt;http://localhost/dayofmonthservice.php&lt;/i&gt; in the client samples.&lt;/p&gt;

&lt;p&gt;To use PHP with IIS, you might need to install it through Microsoft’s &lt;a href="http://www.microsoft.com/web/downloads/platform.aspx" target="_blank"&gt;Web platform installer&lt;/a&gt; or the server-side code won’t execute properly. After PHP installation, try entering a URI for a local PHP page in your browser. If you get an error message that says “Handler PHP53_via_FastCGI has a bad module�� (yeah, that’s really helpful!), return to the Turn Windows features on or off dialog shown earlier, go to &lt;b&gt;Internet Information Services&lt;/b&gt; &amp;gt; &lt;b&gt;World Wide Web Services&lt;/b&gt; &lt;b&gt;&amp;gt; Application Development Features&lt;/b&gt;, check the box for &lt;b&gt;CGI&lt;/b&gt;, and press &lt;b&gt;OK&lt;/b&gt;. After the CGI engine is installed, your PHP page should work.&lt;/p&gt;

&lt;p&gt;With your localhost in place, you can then debug services on your own machine using Visual Studio Express for Web or Visual Studio Ultimate. You can also use Visual Studio Express for Web alongside Visual Studio Express for Windows to debug client and server code together.&lt;/p&gt;

&lt;p&gt;When you run a service or website in the Visual Studio (for Web) debugger, it runs in the browser at a URL like &lt;i&gt;http://localhost:&amp;lt;port&amp;gt;/&lt;/i&gt; where &amp;lt;port&amp;gt; is randomly assigned for that project. For example, when I run the DefaultNE.aspx page from the previous section in Visual Studio Express for Web, that page opens in Internet Explorer with the URI of &lt;i&gt;http://localhost:52568/HelloTiles/DefaultNE.aspx. &lt;/i&gt;If I’ve set a breakpoint in that page’s code, the debugger immediately stops at that point.&lt;/p&gt;

&lt;p&gt;Breakpoints are also hit if you use that same localhost URI in client code to initiate requests. So, for example, if I’m running the Push and periodic notifications client side sample in Visual Studio Express for Windows and paste the URI into scenario 4, Visual Studio Express for Web will stop my service in the debugger as soon as Windows makes a request. I can then step through that code (Windows is fortunately patient) and make sure the right response is being generated. If not, I can fix the code and restart the service on the localhost.&lt;/p&gt;

&lt;p&gt;When you’re confident that your service is operating as intended, you can then upload it to your live web host (or staging environment) and do your final production testing.&lt;/p&gt;

&lt;p&gt;Note that it’s not necessary to run client code in a debugger to use the localhost in this way. If you do, however, there’s an option in Visual Studio that must be turned on for localhost to work. It’s checked by default, but if you need to change it, you’ll find it in you project properties under &lt;b&gt;Debugging&lt;/b&gt; &amp;gt; &lt;b&gt;Allow Local Network Loopback&lt;/b&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/4186.pushandperiodic_5F00_7DB809E8.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="The Allow Local Network Loopback option " border="0" alt="The Allow Local Network Loopback option " src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8132.pushandperiodic_5F00_thumb_5F00_32586624.png" width="700" height="496" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Data from external sources&lt;/h2&gt;

&lt;p&gt;In addition to querying its own database, it’s entirely possible for a periodic notification service to send requests to other services to obtain data for its response. The caveat, however, is that such requests are asynchronous in nature and are prone to a variety of failure conditions. As such, using them can greatly complicate the implementation of your service.&lt;/p&gt;

&lt;p&gt;To simplify matters, we can take advantage of the fact that Windows only makes requests to your service at 30-minute or longer intervals, as enforced by the client API. This means you have lots of time during which other server-side processes can make external requests to monitor weather alerts, leaderboards, RSS feeds, and just about anything else for which there’s a web API. Those processes store results in your database, which are then ready for your periodic notification service to query (synchronously) when it receives its next request.&lt;/p&gt;

&lt;p&gt;Indeed, any number of agents can update the same database. For example, users might be entering data through your website. They might be using mobile phone apps to track their activities, with results being automatically uploaded to a database. The database might also be getting updated by friends who are using the same app on their individual devices.&lt;/p&gt;

&lt;p&gt;Such an arrangement is shown below, where the database serves as the central store for your back-end state and the periodic notification service acts only as a simple consumer of that state.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1768.database_5F00_servers_5F00_graph_5F00_03FEE077.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="database_servers_graph" border="0" alt="database_servers_graph" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/4405.database_5F00_servers_5F00_graph_5F00_thumb_5F00_7CDFA3FE.png" width="700" height="330" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Using Windows Azure Mobile Services with periodic update services&lt;/h2&gt;

&lt;p&gt;As you begin to understand and build out back-end services to support live tiles and other notifications, you really owe it to yourself to explore &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started/" target="_blank"&gt;Windows Azure Mobile Services&lt;/a&gt;, which I’ll refer to as AMS for short. In addition to greatly simplifying push notifications, as we’ll see in Part 3 of this series, AMS can be used to support periodic updates services in several ways:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In a mobile service you can create scheduled background jobs that can make requests to other services and store the results in your database. An example of this, to obtain tweets from Twitter, can be found on the &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/schedule-backend-tasks/" target="_blank"&gt;Schedule recurring jobs in Mobile Services&lt;/a&gt; topic.&lt;/li&gt;

  &lt;li&gt;When you create a SQL Server database in AMS (or elsewhere in Windows Azure), that database is accessible like any other web-hosted SQL Server database, so you can use it from websites and other services, including those written in PHP.&lt;/li&gt;

  &lt;li&gt;AMS makes it very easy to insert records into a database from a client app, using the &lt;a href="http://www.windowsazure.com/en-us/develop/mobile/developer-tools/" target="_blank"&gt;Mobile Services SDK&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;Separate from mobile services, Windows Azure can host server-side processes written in a variety of languages, including Node.js, Python, Java, PHP, and .NET.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the future, also watch for a new feature called “service operations” In Azure Mobile Services, through which you will be able to create arbitrary http endpoints, including a periodic notification service.&lt;/p&gt;

&lt;p&gt;For more information about Windows Azure, visit &lt;a href="http://www.windowsazure.com" target="_blank"&gt;http://www.windowsazure.com&lt;/a&gt;. For introductory videos, also visit &lt;a href="http://channel9.msdn.com/Series/Windows-Azure-Mobile-Services" target="_blank"&gt;Windows Azure Mobile Services Tutorials&lt;/a&gt; on Channel 9.&lt;/p&gt;

&lt;p&gt;Having now explored how to create periodic notification services, we’re ready to take the next step into push notifications. Push notifications are necessary when you need to issue updates more frequently than periodic notifications allow, essentially on demand (hence the name, “push”). This is the topic that we’ll return to in Part 3 of this series, where we’ll see much more of Azure Mobile Services.&lt;/p&gt;

&lt;p&gt;Kraig Brockschmidt
  &lt;br /&gt;Program Manager, Windows Ecosystem Team 

  &lt;br /&gt;Author, &lt;a href="http://blogs.msdn.com/b/microsoft_press/archive/2012/10/29/free-ebook-programming-windows-8-apps-with-html-css-and-javascript.aspx" target="_blank"&gt;Programming Windows 8 Apps in HTML, CSS, and JavaScript&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10397967" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/live+tiles/">live tiles</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/debugging+live+tiles/">debugging live tiles</category><category domain="http://blogs.msdn.com/b/windowsappdev/archive/tags/Windows+8+live+tiles/">Windows 8 live tiles</category></item></channel></rss>