the windows runtime and the web
DESCRIPTION
The Windows Runtime is the runtime that drives Windows 8 and the new Windows Store apps. The runtime enables developers to build rich client apps that run natively on Window 8 devices. In this session, Jeremy Likness explores the various built-in components and APIs that enable Windows Store apps to connect to SOAP, REST, and OData endpoints and syndicate RSS and Atom feeds. Learn how these tools make it easy to build Windows Store apps that are alive and connected to the internet.TRANSCRIPT
![Page 1: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/1.jpg)
Consulting/Training
Jeremy Likness
Principal Consultant
@JeremyLikness
WinRT and the Web: Keeping Windows Store Apps Alive and Connected
![Page 2: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/2.jpg)
Consulting/Training
consultingWintellect helps you build better software, faster, tackling the tough projects and solving the software and technology questions that help you transform your business. Architecture, Analysis and Design Full lifecycle software development Debugging and Performance tuning Database design and development
trainingWintellect's courses are written and taught by some of the biggest and most respected names in the Microsoft programming industry. Learn from the best. Access the same
training Microsoft’s developers enjoy Real world knowledge and solutions
on both current and cutting edge technologies
Flexibility in training options – onsite, virtual, on demand
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.
who we are
About Wintellect
![Page 3: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/3.jpg)
Consulting/Training
Programming the Windows Runtime by Example
http://bit.ly/winrtexample
http://winrtexamples.codeplex.com/
![Page 4: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/4.jpg)
Consulting/Training
WinRT and .NET WebViewSimple: HTTP (REST) OData (WCF Data Services) Syndication SOAP Sockets Mobile ServicesLive Tiles
Agenda
![Page 5: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/5.jpg)
Consulting/Training
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
WinRT and .NET
![Page 6: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/6.jpg)
Consulting/Training
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
WebView Control
![Page 7: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/7.jpg)
Consulting/Training
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);
WebView Control
![Page 8: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/8.jpg)
Consulting/Training
WebViewExamples from Chapter03 http://winrtexamples.codeplex.com/
The Embedded Browser: Using WebView
![Page 9: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/9.jpg)
Consulting/Training
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
HttpClient
![Page 10: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/10.jpg)
Consulting/Training
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);
HttpClient (and a little JSON help)
![Page 11: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/11.jpg)
Consulting/Training
RESTService Example from Chapter05 http://winrtexamples.codeplex.com/
Parsing a REST service with HttpClient and JSON
![Page 12: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/12.jpg)
Consulting/Training
AdvancedHttpExample Example from Chapter10 http://winrtexamples.codeplex.com/
Advanced HTTP Downloads
![Page 13: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/13.jpg)
Consulting/Training
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)
OData (WCF Services)
![Page 14: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/14.jpg)
Consulting/Training
OData (WCF Data Services)
![Page 15: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/15.jpg)
Consulting/Training
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);
OData Client Proxy
![Page 16: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/16.jpg)
Consulting/Training
ODataServiceExample from Chapter05 http://winrtexamples.codeplex.com/
Connecting to OData using WCF Data Services
![Page 17: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/17.jpg)
Consulting/Training
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)
Syndication (Atom/RSS)
![Page 18: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/18.jpg)
Consulting/Training
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)
Feed Syndication
![Page 19: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/19.jpg)
Consulting/Training
SyndicationExample from Chapter05 http://winrtexamples.codeplex.com/
Syndicating a Feed
![Page 20: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/20.jpg)
Consulting/Training
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
SOAP
![Page 21: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/21.jpg)
Consulting/Training
SOAP
![Page 22: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/22.jpg)
Consulting/Training
var proxy = new WeatherSoapClient();
var result = await proxy.GetWeatherInformationAsync();
foreach (var item in result.GetWeatherInformationResult)
{
this.weather.Add(item);
}
SOAP Proxy (Generated Client)
![Page 23: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/23.jpg)
Consulting/Training
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;
}
SOAP Proxy (Channel Factory)
![Page 24: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/24.jpg)
Consulting/Training
SoapServiceExample from Chapter05 http://winrtexamples.codeplex.com/
Connecting to SOAP-based Web Services
![Page 25: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/25.jpg)
Consulting/Training
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
Sockets
![Page 26: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/26.jpg)
Consulting/Training
WebSocketExamples from Chapter10 http://winrtexamples.codeplex.com/
WebSockets
![Page 27: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/27.jpg)
Consulting/Training
SocketsGame from Chapter10 http://winrtexamples.codeplex.com/
TCP Sockets
![Page 28: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/28.jpg)
Consulting/Training
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
Windows Azure Mobile Services
![Page 29: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/29.jpg)
Consulting/Training
Windows Azure Mobile Services
![Page 30: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/30.jpg)
Consulting/Training
Windows Azure Mobile Services
![Page 31: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/31.jpg)
Consulting/Training
Windows Azure Mobile Services
![Page 32: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/32.jpg)
Consulting/Training
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);
Windows Azure Mobile Services
![Page 33: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/33.jpg)
Consulting/Training
Tiles and Notifications
![Page 34: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/34.jpg)
Consulting/Training
LiveConnectExample from Chapter06 http://winrtexamples.codeplex.com/
Bonus Example - LiveConnect
![Page 35: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/35.jpg)
Consulting/Training
WinRT and .NET WebViewSimple: HTTP (REST) OData (WCF Data Services) Syndication SOAP Sockets Mobile ServicesLive Tiles
Recap
![Page 36: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/36.jpg)
Consulting/Training
Subscribers Enjoy
Expert Instructors
Quality Content
Practical Application
All Devices
Wintellect’s On-DemandVideo Training Solution
Individuals | Businesses | Enterprise Organizations
WintellectNOW.com
Authors Enjoy
Royalty Income
Personal Branding
Free Library Access
Cross-Sell Opportunities
Try It Free! Use Promo Code:
LIKNESS-2013
![Page 37: The Windows Runtime and the Web](https://reader035.vdocuments.net/reader035/viewer/2022062616/54954468b4795976588b4823/html5/thumbnails/37.jpg)
Consulting/Training
Questions?
Jeremy Likness
Principal Consultant
@JeremyLikness