SlideShare a Scribd company logo
WinRT and the Web: Keeping
Windows Store Apps Alive and
Connected

Consulting/Training
About Wintellect
who we are
Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull
out all the stops to help our customers achieve their goals through advanced software-based
consulting and training solutions.

consulting

training

Wintellect helps you build better software,
faster, tackling the tough projects and solving
the software and technology questions that
help you transform your business.

Wintellect's courses are written and taught by
some of the biggest and most respected names
in the Microsoft programming industry.






Architecture, Analysis and Design

training Microsoft’s developers enjoy

Full lifecycle software development

 Real world knowledge and solutions on

Debugging and Performance tuning
Database design and development

 Learn from the best. Access the same
both current and cutting edge
technologies

 Flexibility in training options – onsite,
virtual, on demand

Consulting/Training
Programming the Windows Runtime
by Example
http://bit.ly/winrtexample
http://winrtexamples.codeplex.com/

Consulting/Training
Agenda










WinRT and .NET
WebView
Simple: HTTP (REST)
OData (WCF Data Services)
Syndication
SOAP
Sockets
Mobile Services
Live Tiles
Consulting/Training
WinRT and .NET
 Most .NET network classes are available to






Windows Store apps for Windows 8.1
Windows Store apps written in C# have
access to a limited .NET profile, in addition to
WinRT components provided via projection
Many network components have been
moved into WinRT (i.e. the HttpClient)
Other features include proxies that generate
pure .NET code as a function of the IDE (i.e.
“add service reference”
We’ll focus on C# but the WinRT components
are valid for C++ and JavaScript too

Consulting/Training
WebView Control
 Internet Explorer 11 control
 Direct Composition surface so it can be

translated/transformed and overlaid (this
wasn’t the case in Windows 8, only 8.1)

 Capable of rendering SVG and WebGL
 Interoperability with the Windows Store
app (can call to scripts on the page and
vice versa)

 Navigation methods (history, journal)
built-in

Consulting/Training
WebView Control
this.WebViewControl.Navigate(new Uri(JeremyBlog));
this.WebViewControl.Navigate(new
Uri("ms-appx-web:///Data/Ellipse.html"));
// can also navigate to streams with a special URI handler in 8.1

this.WebViewControl.NavigateToString(HtmlFragment);
var parameters = new[] { "p/biography.html" };
this.WebViewControl.InvokeScript(
"superSecretBiographyFunction",
parameters);

Consulting/Training
The Embedded Browser: Using WebView
WebViewExamples from Chapter03 http://winrtexamples.codeplex.com/

Consulting/Training
HttpClient
 WinRT as of 8.1
 Pure control over HTTP
 Viable for REST i.e. serialize/deserialize






directly from JSON and/or XML
Control headers and manage response
as text, stream, etc.
GET, POST, PUT, and DELETE
Using HttpRequestMessage for custom
verbs, etc.
Base class for more specialized clients

Consulting/Training
HttpClient (and a little JSON help)
private static readonly MediaTypeWithQualityHeaderValue Json = new
MediaTypeWithQualityHeaderValue("application/json");
string jsonResponse;
using (var client = new HttpClient())

{
client.DefaultRequestHeaders.Accept.Add(Json);
jsonResponse = await client.GetStringAsync(productsUri);
}
var json = JsonObject.Parse(jsonResponse);

Consulting/Training
Parsing a REST service with HttpClient and JSON
RESTService Example from Chapter05 http://winrtexamples.codeplex.com/

Consulting/Training
Advanced HTTP Downloads
AdvancedHttpExample Example from Chapter10 http://winrtexamples.codeplex.com/

Consulting/Training
OData (WCF Services)
 http://bit.ly/1gq5Obu
 Add-on for Visual Studio 2013
 Allows right-click and add
reference for service

 Generates the proxy and

structures using a data context
(similar to Entity Framework /
WCF RIA)

Consulting/Training
OData (WCF Data Services)

Consulting/Training
OData Client Proxy
ServiceBase = new Uri("http://services.odata.org/OData/OData.svc",
UriKind.Absolute);
var client = new ODataService.DemoService(ServiceBase);
var categoryQuery = client.Categories.AddQueryOption("$expand",
"Products");
var categories = await Task<IEnumerable<ODataService.Category>>
.Factory.FromAsync(
categoryQuery.BeginExecute(result => { }, client),
categoryQuery.EndExecute);

Consulting/Training
Connecting to OData using WCF Data Services
ODataServiceExample from Chapter05 http://winrtexamples.codeplex.com/

Consulting/Training
Syndication (Atom/RSS)
 WinRT (mirrors the .NET equivalent
very closely)

 Parses Atom and RSS
 Suitable for both consuming and
publishing

 Also capable of converting

between formats (i.e. read an Atom
and serve an RSS)

Consulting/Training
Feed Syndication
private static readonly Uri CSharperImageUri = new Uri(
"http://feeds.feedburner.com/CSharperImage/", UriKind.Absolute);
var client = new SyndicationClient();
var feed = await client.RetrieveFeedAsync(CSharperImageUri);

var group = new DataFeed(feed.Id, feed.Title.Text, AuthorSignature,
feed.ImageUri.ToString(), feed.Subtitle.Text);
from item in feed.Items
let content =
Windows.Data.Html.HtmlUtilities.ConvertToText(item.Content.Text)
let summary = string.Format("{0} ...", content.Length > 255 ?
content.Substring(0, 255) : content)

Consulting/Training
Syndicating a Feed
SyndicationExample from Chapter05 http://winrtexamples.codeplex.com/

Consulting/Training
SOAP
 IDE provides similar interface to OData
 Uses WSDL to understand the shape of the service
 Considered a more complicated protocol but is
very widely used and has built-in security,
encryption, and other features that are beneficial
to the enterprise

 Generates a proxy (client) that is used to handle
the communications (RPC-based)

 Can also use channel factories to create clients
Consulting/Training
SOAP

Consulting/Training
SOAP Proxy (Generated Client)
var proxy = new WeatherSoapClient();
var result = await proxy.GetWeatherInformationAsync();
foreach (var item in result.GetWeatherInformationResult)
{
this.weather.Add(item);
}

Consulting/Training
SOAP Proxy (Channel Factory)
using (
var factory = new ChannelFactory<WeatherSoapChannel>(
new BasicHttpBinding(), new
EndpointAddress("http://wsf.cdyne.com/WeatherWS/Weather.asmx")))
{
var channel = factory.CreateChannel();
var forecast = await channel.GetCityForecastByZIPAsync(zipCode);
var result = forecast.AsWeatherForecast();
foreach (var day in result.Forecast)
{
day.ForecastUri = await this.GetImageUriForType(day.TypeId);
}
return result;
}
Consulting/Training
Connecting to SOAP-based Web Services
SoapServiceExample from Chapter05 http://winrtexamples.codeplex.com/

Consulting/Training
Sockets
 HTTP sits on top of TCP
 Sockets communicate at a lower level – TCP/UDP
 Newer WebSockets protocol for HTML5 uses HTTP
ports for a simpler sockets interface

 Use for real-time bi-directional communication
 Windows 8.1 can be a “server” … process isolation
makes it impractical except as demos, but works
fine as a client

Consulting/Training
WebSockets
WebSocketExamples from Chapter10 http://winrtexamples.codeplex.com/

Consulting/Training
TCP Sockets
SocketsGame from Chapter10 http://winrtexamples.codeplex.com/

Consulting/Training
Windows Azure Mobile Services
 Affectionately referred to as WAMS
 Literally right-click and “add Connected Service”
 Create simple CRUD and other types of services
using hosted SQL

 Create push notifications for live updates and
notifications within your app

Consulting/Training
Windows Azure Mobile Services

Consulting/Training
Windows Azure Mobile Services

Consulting/Training
Windows Azure Mobile Services

Consulting/Training
Windows Azure Mobile Services
public static MobileServiceClient WinRTByExampleBookClient =
new MobileServiceClient(
"https://MOBILESERVICENAME.azure-mobile.net/",
"APPLICATION KEY");
// query
var table = App.WinRTByExampleBookClient.GetTable<Subscriber>();
var query = table.CreateQuery()
.OrderBy(x => x.LastName)
.ThenBy(x => x.FirstName);
Subscribers = query.ToIncrementalLoadingCollection();
// insert
var table = App.WinRTByExampleBookClient.GetTable<Subscriber>();
await table.InsertAsync(SubscriberBeingEdited);

Consulting/Training
Tiles and Notifications

Consulting/Training
Bonus Example - LiveConnect
LiveConnectExample from Chapter06 http://winrtexamples.codeplex.com/

Consulting/Training
Recap










WinRT and .NET
WebView
Simple: HTTP (REST)
OData (WCF Data Services)
Syndication
SOAP
Sockets
Mobile Services
Live Tiles
Consulting/Training
Wintellect’s On-Demand
Video Training Solution
WintellectNOW.com
Subscribers Enjoy

Try It Free!
Use Promo Code:
LIKNESS-2013

Authors Enjoy

 Expert Instructors

 Royalty Income

 Quality Content

 Personal Branding

 Practical Application

 Free Library Access

 All Devices

 Cross-Sell

Opportunities

Individuals | Businesses | Enterprise Organizations
Consulting/Training
Questions?

jlikness@Wintellect.com

Consulting/Training

More Related Content

The Windows Runtime and the Web

  • 1. WinRT and the Web: Keeping Windows Store Apps Alive and Connected Consulting/Training
  • 2. About Wintellect who we are Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions. consulting training Wintellect helps you build better software, faster, tackling the tough projects and solving the software and technology questions that help you transform your business. Wintellect's courses are written and taught by some of the biggest and most respected names in the Microsoft programming industry.     Architecture, Analysis and Design training Microsoft’s developers enjoy Full lifecycle software development  Real world knowledge and solutions on Debugging and Performance tuning Database design and development  Learn from the best. Access the same both current and cutting edge technologies  Flexibility in training options – onsite, virtual, on demand Consulting/Training
  • 3. Programming the Windows Runtime by Example http://bit.ly/winrtexample http://winrtexamples.codeplex.com/ Consulting/Training
  • 4. Agenda          WinRT and .NET WebView Simple: HTTP (REST) OData (WCF Data Services) Syndication SOAP Sockets Mobile Services Live Tiles Consulting/Training
  • 5. WinRT and .NET  Most .NET network classes are available to     Windows Store apps for Windows 8.1 Windows Store apps written in C# have access to a limited .NET profile, in addition to WinRT components provided via projection Many network components have been moved into WinRT (i.e. the HttpClient) Other features include proxies that generate pure .NET code as a function of the IDE (i.e. “add service reference” We’ll focus on C# but the WinRT components are valid for C++ and JavaScript too Consulting/Training
  • 6. WebView Control  Internet Explorer 11 control  Direct Composition surface so it can be translated/transformed and overlaid (this wasn’t the case in Windows 8, only 8.1)  Capable of rendering SVG and WebGL  Interoperability with the Windows Store app (can call to scripts on the page and vice versa)  Navigation methods (history, journal) built-in Consulting/Training
  • 7. WebView Control this.WebViewControl.Navigate(new Uri(JeremyBlog)); this.WebViewControl.Navigate(new Uri("ms-appx-web:///Data/Ellipse.html")); // can also navigate to streams with a special URI handler in 8.1 this.WebViewControl.NavigateToString(HtmlFragment); var parameters = new[] { "p/biography.html" }; this.WebViewControl.InvokeScript( "superSecretBiographyFunction", parameters); Consulting/Training
  • 8. The Embedded Browser: Using WebView WebViewExamples from Chapter03 http://winrtexamples.codeplex.com/ Consulting/Training
  • 9. HttpClient  WinRT as of 8.1  Pure control over HTTP  Viable for REST i.e. serialize/deserialize     directly from JSON and/or XML Control headers and manage response as text, stream, etc. GET, POST, PUT, and DELETE Using HttpRequestMessage for custom verbs, etc. Base class for more specialized clients Consulting/Training
  • 10. HttpClient (and a little JSON help) private static readonly MediaTypeWithQualityHeaderValue Json = new MediaTypeWithQualityHeaderValue("application/json"); string jsonResponse; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(Json); jsonResponse = await client.GetStringAsync(productsUri); } var json = JsonObject.Parse(jsonResponse); Consulting/Training
  • 11. Parsing a REST service with HttpClient and JSON RESTService Example from Chapter05 http://winrtexamples.codeplex.com/ Consulting/Training
  • 12. Advanced HTTP Downloads AdvancedHttpExample Example from Chapter10 http://winrtexamples.codeplex.com/ Consulting/Training
  • 13. OData (WCF Services)  http://bit.ly/1gq5Obu  Add-on for Visual Studio 2013  Allows right-click and add reference for service  Generates the proxy and structures using a data context (similar to Entity Framework / WCF RIA) Consulting/Training
  • 14. OData (WCF Data Services) Consulting/Training
  • 15. OData Client Proxy ServiceBase = new Uri("http://services.odata.org/OData/OData.svc", UriKind.Absolute); var client = new ODataService.DemoService(ServiceBase); var categoryQuery = client.Categories.AddQueryOption("$expand", "Products"); var categories = await Task<IEnumerable<ODataService.Category>> .Factory.FromAsync( categoryQuery.BeginExecute(result => { }, client), categoryQuery.EndExecute); Consulting/Training
  • 16. Connecting to OData using WCF Data Services ODataServiceExample from Chapter05 http://winrtexamples.codeplex.com/ Consulting/Training
  • 17. Syndication (Atom/RSS)  WinRT (mirrors the .NET equivalent very closely)  Parses Atom and RSS  Suitable for both consuming and publishing  Also capable of converting between formats (i.e. read an Atom and serve an RSS) Consulting/Training
  • 18. Feed Syndication private static readonly Uri CSharperImageUri = new Uri( "http://feeds.feedburner.com/CSharperImage/", UriKind.Absolute); var client = new SyndicationClient(); var feed = await client.RetrieveFeedAsync(CSharperImageUri); var group = new DataFeed(feed.Id, feed.Title.Text, AuthorSignature, feed.ImageUri.ToString(), feed.Subtitle.Text); from item in feed.Items let content = Windows.Data.Html.HtmlUtilities.ConvertToText(item.Content.Text) let summary = string.Format("{0} ...", content.Length > 255 ? content.Substring(0, 255) : content) Consulting/Training
  • 19. Syndicating a Feed SyndicationExample from Chapter05 http://winrtexamples.codeplex.com/ Consulting/Training
  • 20. SOAP  IDE provides similar interface to OData  Uses WSDL to understand the shape of the service  Considered a more complicated protocol but is very widely used and has built-in security, encryption, and other features that are beneficial to the enterprise  Generates a proxy (client) that is used to handle the communications (RPC-based)  Can also use channel factories to create clients Consulting/Training
  • 22. SOAP Proxy (Generated Client) var proxy = new WeatherSoapClient(); var result = await proxy.GetWeatherInformationAsync(); foreach (var item in result.GetWeatherInformationResult) { this.weather.Add(item); } Consulting/Training
  • 23. SOAP Proxy (Channel Factory) using ( var factory = new ChannelFactory<WeatherSoapChannel>( new BasicHttpBinding(), new EndpointAddress("http://wsf.cdyne.com/WeatherWS/Weather.asmx"))) { var channel = factory.CreateChannel(); var forecast = await channel.GetCityForecastByZIPAsync(zipCode); var result = forecast.AsWeatherForecast(); foreach (var day in result.Forecast) { day.ForecastUri = await this.GetImageUriForType(day.TypeId); } return result; } Consulting/Training
  • 24. Connecting to SOAP-based Web Services SoapServiceExample from Chapter05 http://winrtexamples.codeplex.com/ Consulting/Training
  • 25. Sockets  HTTP sits on top of TCP  Sockets communicate at a lower level – TCP/UDP  Newer WebSockets protocol for HTML5 uses HTTP ports for a simpler sockets interface  Use for real-time bi-directional communication  Windows 8.1 can be a “server” … process isolation makes it impractical except as demos, but works fine as a client Consulting/Training
  • 26. WebSockets WebSocketExamples from Chapter10 http://winrtexamples.codeplex.com/ Consulting/Training
  • 27. TCP Sockets SocketsGame from Chapter10 http://winrtexamples.codeplex.com/ Consulting/Training
  • 28. Windows Azure Mobile Services  Affectionately referred to as WAMS  Literally right-click and “add Connected Service”  Create simple CRUD and other types of services using hosted SQL  Create push notifications for live updates and notifications within your app Consulting/Training
  • 29. Windows Azure Mobile Services Consulting/Training
  • 30. Windows Azure Mobile Services Consulting/Training
  • 31. Windows Azure Mobile Services Consulting/Training
  • 32. Windows Azure Mobile Services public static MobileServiceClient WinRTByExampleBookClient = new MobileServiceClient( "https://MOBILESERVICENAME.azure-mobile.net/", "APPLICATION KEY"); // query var table = App.WinRTByExampleBookClient.GetTable<Subscriber>(); var query = table.CreateQuery() .OrderBy(x => x.LastName) .ThenBy(x => x.FirstName); Subscribers = query.ToIncrementalLoadingCollection(); // insert var table = App.WinRTByExampleBookClient.GetTable<Subscriber>(); await table.InsertAsync(SubscriberBeingEdited); Consulting/Training
  • 34. Bonus Example - LiveConnect LiveConnectExample from Chapter06 http://winrtexamples.codeplex.com/ Consulting/Training
  • 35. Recap          WinRT and .NET WebView Simple: HTTP (REST) OData (WCF Data Services) Syndication SOAP Sockets Mobile Services Live Tiles Consulting/Training
  • 36. Wintellect’s On-Demand Video Training Solution WintellectNOW.com Subscribers Enjoy Try It Free! Use Promo Code: LIKNESS-2013 Authors Enjoy  Expert Instructors  Royalty Income  Quality Content  Personal Branding  Practical Application  Free Library Access  All Devices  Cross-Sell Opportunities Individuals | Businesses | Enterprise Organizations Consulting/Training

Editor's Notes

  1. Author Opportunity Passive incomeClear marketing commitments to help grow your personal brand and your coursesInternational presence &amp; exposureCross sell opportunities – instructor led classes, consulting opportunities, and conference speaking opportunitiesOpportunity to be the subject matter expert and to carve out a niche for yourself in this new businessAssociation with Wintellect