61
Windows 8, Metro apps and the outside world SILVERLIGHTSHOW.NET WEBINARS SERIES GILL CLEEREN, 15 th August 2012 www.snowball.be - [email protected] - @gillcleeren

Windows 8 Metro apps and the outside world

Embed Size (px)

Citation preview

Page 1: Windows 8 Metro apps and the outside world

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

Agenda

bull Accessing data behind a servicebull Working with WCF and ASMX servicesbull Working with REST servicesbull Accessing oData servicesbull Syndication with RSSbull Authenticating with Twitter and Facebook using the

WebAuthBrokerbull Using the Live SDK in your Windows 8 appsbull Using roaming data in your applicationsbull Working with sockets

ndash TCP socketsndash WebSockets

bull Setting the correct capabilities for network communication

ACCESSING DATA BEHIND A SERVICE

Working with services to access data

bull Service communication is always done asynchronousndash In Silverlight this was done using a callbackndash In C5 we got the asyncawait keywords

bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread

ndash Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)

bull Getting data in a Metro application is a 3-step processndash Calling the service asynchronousndash Receiving and parsing the datandash Using the data for example in a data-binding scenario

Working with services to access data

bull Working with services is preferred in most casesndash Relational databases should be behind a servicendash Local app storagebull App has its own storage directorybull Can access local file systembull Not the focus of this talk

Working with services

bull Windows 8 supports all kinds of servicesndash ASMXndash WCFndash REST (JSON or XML)ndash RSS (later in this talk)ndash Sockets (much later in this talk)ndash oData services (you get the drill itrsquos also further in this

talkhellip)ndash No WCF RIA Services support out-of-the-box though (so

yes that is NOT in this talk )ndash hellip

WCF AND ASMX SERVICES

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 2: Windows 8 Metro apps and the outside world

Agenda

bull Accessing data behind a servicebull Working with WCF and ASMX servicesbull Working with REST servicesbull Accessing oData servicesbull Syndication with RSSbull Authenticating with Twitter and Facebook using the

WebAuthBrokerbull Using the Live SDK in your Windows 8 appsbull Using roaming data in your applicationsbull Working with sockets

ndash TCP socketsndash WebSockets

bull Setting the correct capabilities for network communication

ACCESSING DATA BEHIND A SERVICE

Working with services to access data

bull Service communication is always done asynchronousndash In Silverlight this was done using a callbackndash In C5 we got the asyncawait keywords

bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread

ndash Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)

bull Getting data in a Metro application is a 3-step processndash Calling the service asynchronousndash Receiving and parsing the datandash Using the data for example in a data-binding scenario

Working with services to access data

bull Working with services is preferred in most casesndash Relational databases should be behind a servicendash Local app storagebull App has its own storage directorybull Can access local file systembull Not the focus of this talk

Working with services

bull Windows 8 supports all kinds of servicesndash ASMXndash WCFndash REST (JSON or XML)ndash RSS (later in this talk)ndash Sockets (much later in this talk)ndash oData services (you get the drill itrsquos also further in this

talkhellip)ndash No WCF RIA Services support out-of-the-box though (so

yes that is NOT in this talk )ndash hellip

WCF AND ASMX SERVICES

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 3: Windows 8 Metro apps and the outside world

ACCESSING DATA BEHIND A SERVICE

Working with services to access data

bull Service communication is always done asynchronousndash In Silverlight this was done using a callbackndash In C5 we got the asyncawait keywords

bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread

ndash Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)

bull Getting data in a Metro application is a 3-step processndash Calling the service asynchronousndash Receiving and parsing the datandash Using the data for example in a data-binding scenario

Working with services to access data

bull Working with services is preferred in most casesndash Relational databases should be behind a servicendash Local app storagebull App has its own storage directorybull Can access local file systembull Not the focus of this talk

Working with services

bull Windows 8 supports all kinds of servicesndash ASMXndash WCFndash REST (JSON or XML)ndash RSS (later in this talk)ndash Sockets (much later in this talk)ndash oData services (you get the drill itrsquos also further in this

talkhellip)ndash No WCF RIA Services support out-of-the-box though (so

yes that is NOT in this talk )ndash hellip

WCF AND ASMX SERVICES

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 4: Windows 8 Metro apps and the outside world

Working with services to access data

bull Service communication is always done asynchronousndash In Silverlight this was done using a callbackndash In C5 we got the asyncawait keywords

bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread

ndash Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)

bull Getting data in a Metro application is a 3-step processndash Calling the service asynchronousndash Receiving and parsing the datandash Using the data for example in a data-binding scenario

Working with services to access data

bull Working with services is preferred in most casesndash Relational databases should be behind a servicendash Local app storagebull App has its own storage directorybull Can access local file systembull Not the focus of this talk

Working with services

bull Windows 8 supports all kinds of servicesndash ASMXndash WCFndash REST (JSON or XML)ndash RSS (later in this talk)ndash Sockets (much later in this talk)ndash oData services (you get the drill itrsquos also further in this

talkhellip)ndash No WCF RIA Services support out-of-the-box though (so

yes that is NOT in this talk )ndash hellip

WCF AND ASMX SERVICES

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 5: Windows 8 Metro apps and the outside world

Working with services to access data

bull Working with services is preferred in most casesndash Relational databases should be behind a servicendash Local app storagebull App has its own storage directorybull Can access local file systembull Not the focus of this talk

Working with services

bull Windows 8 supports all kinds of servicesndash ASMXndash WCFndash REST (JSON or XML)ndash RSS (later in this talk)ndash Sockets (much later in this talk)ndash oData services (you get the drill itrsquos also further in this

talkhellip)ndash No WCF RIA Services support out-of-the-box though (so

yes that is NOT in this talk )ndash hellip

WCF AND ASMX SERVICES

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 6: Windows 8 Metro apps and the outside world

Working with services

bull Windows 8 supports all kinds of servicesndash ASMXndash WCFndash REST (JSON or XML)ndash RSS (later in this talk)ndash Sockets (much later in this talk)ndash oData services (you get the drill itrsquos also further in this

talkhellip)ndash No WCF RIA Services support out-of-the-box though (so

yes that is NOT in this talk )ndash hellip

WCF AND ASMX SERVICES

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 7: Windows 8 Metro apps and the outside world

WCF AND ASMX SERVICES

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 8: Windows 8 Metro apps and the outside world

ASMX services (aka good old webservices)

bull ASMX services can be accessed without any changebull Communication is done asynchronouslybull SOAP messages can be sent and received over

ASMX servicesbull From Visual Studio use the default way of

connecting with a servicendash Add service referencendash Generates proxy

bull All Task-based

ndash Use proxy-class with the asyncawait keywords

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 9: Windows 8 Metro apps and the outside world

ACCESSING AN ASMX SERVICE FROM WINDOWS 8

DEMO

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 10: Windows 8 Metro apps and the outside world

WCF Servicesbull What is supported

ndash Bindingsbull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding

ndash Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 11: Windows 8 Metro apps and the outside world

WCF Servicesbull What is supported

ndash Encodingbull Text Binary

ndash Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for

BasicHttpBinding) ndash ClientCredentialType

bull None Basic Digest Negotiate Ntlm Windows ndash Transfer Mode

bull Buffered Streamed StreamedRequest and StreamedResponse ndash Serializers

bull DataContractSerializer DataContractJsonSerializer XmlSerializer ndash Miscellaneous

bull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 12: Windows 8 Metro apps and the outside world

Things to note when working with WCF (also goes for ASMX)

bull No XML config file codendash Code gets generated in the Referencecs filebull No config edit possible

ndash Use the partial ConfigureEndpoint methodbull Only Task-based methods are availablendash Ensures there are no blocking callsndash Is done by default

bull Specify Internet capability

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 13: Windows 8 Metro apps and the outside world

What about security for service communication

bull WinRT supports sending credentialsbull When building service that expects credentials

generated code in Referencecs will reflect this

bull https custom validation are supported to enable TransportWithMessageCredential ndash Allows safe passing of usernamepassword to service endpoint

resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly

resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 14: Windows 8 Metro apps and the outside world

REST services

bull No more WebClient replaced with HttpClientndash Works with asyncndash Located in SystemNet

bull HttpClient definesndash Get(Async)

bull Returns an HttpResponseMessage

ndash Put(Async)ndash Post(Async)ndash Delete(Async) RESTful

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 15: Windows 8 Metro apps and the outside world

Parsing the response

bull XMLndash Linq-To-XMLndash XmlReaderXmlWriterndash XmlSerializer

bull JSONndash Use the JsonObject and feed it the returned string

bull We can use the Parse() methodndash Throws error if the returned string is faulty or invalid

bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer

ndash Not recommended

ndash DataContractJsonSerializer is also available

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 16: Windows 8 Metro apps and the outside world

Credential support with REST services

bull If REST service requires authentication WinRT will support it

bull Some samples

HttpClientHandler handler = new HttpClientHandler()handlerUseDefaultCredentials = trueHttpClient client = new HttpClient(handler)

using (var handler = new HttpClientHandler

Credentials = )using (var client = new HttpClient(handler)) var result = await clientGetAsync()

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 17: Windows 8 Metro apps and the outside world

WORKING WITH ODATA SERVICES

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 18: Windows 8 Metro apps and the outside world

What is oData

bull Open Data Protocolbull Design goals

ndash Invent as little as possiblendash Very low barrier of entry

bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines

ndash XML + JSON data representationndash Addressing schemendash Query operatorsndash Metadata

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 19: Windows 8 Metro apps and the outside world

Sample URIs

bull httpodatanetflixcomCatalogndash AtomPub service document list of all collections

bull httpodatanetflixcomCatalogGenresndash all entries of a collection

bull httpCatalogGenres(Adventures)ndash one entry by PK

bull httpCatalogGenres(Adventures)Name ndash one property as XML

bull httpCatalogGenres(Adventures)Name$valuendash only the value

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 20: Windows 8 Metro apps and the outside world

Navigation

bull httpCatalogGenres(Adventures)Titlesndash related entities

bull httpCatalogGenres(Adventures)$linksTitlesndash only the links

bull httpCatalogGenres(Adventures)Titles$countndash count

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 21: Windows 8 Metro apps and the outside world

Queries

bull Titles$filter=AverageRating gt 4ndash filters

bull Titles$orderby=AverageRating desc ReleaseYear ascndash sorting

bull Titles$select=ShortName ReleaseYearndash projection

bull Paging support $top $skip $skiptoken $inlinecount

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 22: Windows 8 Metro apps and the outside world

oData and WinRT

bull Currently therersquos an OData client library available

bull Requires servers that comply with oData v1-v3

bull Support for Add Reference since RCndash Previously we had to use the DataSvcUtil tool to

generate the proxyndash Still works if you want complete control over

the proxy generation

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 23: Windows 8 Metro apps and the outside world

SYNDICATION

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 24: Windows 8 Metro apps and the outside world

Syndication in general

bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries

ndash Postndash Authorndash Datandash Linksndash Fixed set of elements

bull Parsing it is possible ndash Manually (if you like to hurt yourselfhellip)ndash Through a third-party library

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 25: Windows 8 Metro apps and the outside world

Syndication in WinRT

bull WinRT has the WindowsWebSyndication namespacendash Contains SyndicationFeed and SyndicationClient classesndash Allows downloading feed asynchronouslyndash Can be provided with credentials if source requires themndash Supports

bull Atom 03 and 10bull RSS 091 092 10 and 20)

ndash Returns items in an object modelndash Async (Task-based)var client = new SyndicationClient()

SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 26: Windows 8 Metro apps and the outside world

AUTHENTICATING USING THE WEBAUTHBROKER

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 27: Windows 8 Metro apps and the outside world

The WebAuthBroker class

bull The web authentication broker provides a set of APIs and the infrastructure for apps to use Internet authentication and authorization protocols such as Oauthndash When an app calls the web authentication broker

the user gets a dialog box in which the necessary webpages are rendered to sign in

ndash After the user completes those steps the dialog box goes away and the user continues with the app

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 28: Windows 8 Metro apps and the outside world

The WebAuthBroker class

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 29: Windows 8 Metro apps and the outside world

Benefits of the WebAuthBroker

bull An easy-to-use programming interface that frees the app developer from hosting a browser control within their own app

bull User credentials that are isolated from the appbull Native support for single sign-on with online

providersndash Twitterndash Facebookndash Flickrndash hellip

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 30: Windows 8 Metro apps and the outside world

How the WebAuthBroker works

bull The web authentication broker is the facilitator between your app and authentication

bull It consists of a set of APIs a broker and a web host ndash Your app uses the APIs to communicate with the broker ndash The broker creates a new web host process in a separate app

containerndash The broker communicates with the app assembles the UI and controls

the lifecycle of the web authentication hostndash The web authentication host renders the pages from the online

providers website

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 31: Windows 8 Metro apps and the outside world

USING THE LIVE SDK IN YOUR WINDOWS 8 APPS

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 32: Windows 8 Metro apps and the outside world

Live SDK Integration

bull Using the Live SDK we can from WinRT appsndash Leverage SSO functionalityndash Access data in SkyDrivendash Integrate with HotmailOutlook and Messenger

bull Requires the Live SDK 50 to be installed on your systembull Application needs to be registered with Windows Live

ndash httpmanagedevlivecombuild ndash Only need the package name

bull Requires that you are signed in with a Live IDMicrosoft accountndash We can log in using a live account or a local accountndash Itrsquos possible to switch between the two

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 33: Windows 8 Metro apps and the outside world

Live SDK Integration

bull The device has to be trusted ndash In the screenshot below this hasnrsquot been done yet

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 34: Windows 8 Metro apps and the outside world

To integratehellip

bull We can use some of the built-in controls in the SDK

bull Scope ndash A scope grants a permission levelndash Can be

bull wlsignin ndash Single sign-in behavior

bull wlbasicndash Read access to a users basic profile info Also enables read access to a users list of

contacts

bull wlcontacts_createndash Creation of new contacts in the users address book

bull wlcalendars_updatendash Read access to a users personal preferred and business email addresses

bull hellipbull Complete list at httpmsdnmicrosoftcomen-uslibrarylivehh243646aspx

ltliveSignInButton Name=MySignInButton Scopes=wlsignin wlbasic wlcontacts_creategt

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 35: Windows 8 Metro apps and the outside world

Accessing SkyDrive from your apps

bull Windows 8 integrates with SkyDrive (cloud)bull Metro Apps can use SkyDrive through the Live

SDK ndash Enables single sign-on using your Microsoft account

bull Donrsquot bother the user asking to login with every appbull App automatically knows who you arebull Called the easy sign-in

bull Users can use the machine with their Microsoft accountndash Apps can benefit from this as well using Live SDKndash User needs to grant permission though (once)

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 36: Windows 8 Metro apps and the outside world

USING ROAMING DATA IN YOUR APPLICATIONS

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 37: Windows 8 Metro apps and the outside world

Roaming data

bull Users can personalize their devices and settingsbull Windows and the built-in apps create a ldquoconnectedrdquo experience

ndash Configure once use everywherebull Roaming application data makes creating this for us very easy

ndash App data can be local roaming or temporaryndash Roaming will make sure that the data is synced to the cloud and other

devices where the Microsoft account uses the particular app

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 38: Windows 8 Metro apps and the outside world

Roaming data

bull What to place in roaming datandash Data that is relevant to the app that created it

bull Settingsbull Temporary documentbull Level in a gamebull App statebull Context

bull Data that should not be placed in roaming datandash Data that can be readshared with other appsndash Documents pictures exported datandash Data that should be exported to SkyDrive

bull Limit is currently 100kndash Preserve battery and performancendash Can be checked using the RoamingStorageQuota classndash If limit is surpassed no data will be synced at all

bull Itrsquos vital to only sync URIs instead of full pages

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 39: Windows 8 Metro apps and the outside world

Example of roaming data

bull RSS reader app where the user can save how many items he wants to see on his screen

bull If you want to save the last article ID and want to create a continuous experience name the setting HighPriority

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoItemsPerPagerdquo] = 10

WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeedId

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 40: Windows 8 Metro apps and the outside world

Example of roaming data

bull If more than one setting need to be synced together we can use a CompositeSettingValue

bull With the app running the app can register for the DataChanged event on the ApplicationData classndash Will fire when the application data has changed

WindowsStorageApplicationDataCompositeValue currentFeed = new WindowsStorageApplicationDataCompositeValue()currentFeedInsert(ldquoCurrentFeedIdrdquo currentFeedId)currentFeedInsert(ldquoCurrentFeedPagerdquo currentFeedPage)WindowsStorageApplicationDataCurrentRoamingSettingsValues[ldquoHighPriorityrdquo] = currentFeed

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 41: Windows 8 Metro apps and the outside world

Some best practices around roaming data

bull Only works with a Microsoft accountbull The device has to be trusted before roaming data will

workbull Donrsquot use it for simultaneous use of applications on

more than one device at a timendash Last save wins

bull Write often-changing only every now and thenndash Donrsquot use it to constantly write the location within a songndash Writing too often can result in the device being locked-out

for a certain amount of time

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 42: Windows 8 Metro apps and the outside world

WORKING WITH SOCKETS

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 43: Windows 8 Metro apps and the outside world

Types of socket communication in WinRT

bull StreamSocket - Used to support network communication using a TCP stream socket

bull StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket

bull DatagramSocket - Used to support network communication using a UDP datagram socket

bull MessageWebSocket - Used to support network communication that allows reading and writing whole messages using a WebSocket

bull StreamWebSocket - Used to support network communication that allows reading and writing streams using a WebSocket

bull All live in the WindowsNetworkingSockets namespace

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 44: Windows 8 Metro apps and the outside world

When and when not to use sockets

Requirement Solution

Connects to a network service that uses an existing protocol (SMTP POP IMAP or MAPI for mail for example) that is not directly supported by other networking features

TCP or UDP sockets

Connects to another machine on the same local network

TCP or UDP sockets

Requires a simple requestresponse protocol that can communicate through HTTP proxies

Representational State Transfer (REST) APIs that are available using C VBNET and C++

Requires socket-like semantics (asynchronous bi-directional transfers) to connect across the Web including through HTTP proxies

WebSockets

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 45: Windows 8 Metro apps and the outside world

TCP SOCKETS

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 46: Windows 8 Metro apps and the outside world

TCP Sockets

bull TCP and UDP can be used to send and receive data in WinRT apps

bull Based on classes from the WindowsNetworkingSockets namespacendash StreamSocketndash StreamSocketListenerndash DatagramSocket

bull Support forndash Making client connectionsndash Listening for connections ndash Operating as a server or for both client and server operations

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 47: Windows 8 Metro apps and the outside world

TCP Sockets

bull Steps to get TCP sockets working in your Metro appndash Use the StreamSocket class to create a TCP socketndash ConnectAsync on the StreamSocket class allows making a

network connection to a TCP network serverndash StreamsDataWriter allows sending data to the server

bull Basically allows writing common types on a stream

ndash StreamsDataReader allows reading data from a serverbull Basically allows reading common types from a stream

bull StreamSocket object can be configured to use SSLTLS for communications between the client and the serverndash This support for SSLTLS is limited to using the StreamSocket

object as the client in the SSLTLS negotiation

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 48: Windows 8 Metro apps and the outside world

Using the StreamSocket

bull This class enables network communication using a TCP stream socket

bull What you can do with the StreamSocketndash After instantiation of the StreamSocket get a StreamSocketControl

object using the Control property bull Allows setting any properties on the StreamSocketControl object before

calling one of the ConnectAsync methods

ndash Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL

ndash Get the OutputStream property to write data to the remote hostndash Get the InputStream property to read data from the remote hostndash Read and write data as neededndash Call the Close method to abort any pending operations

bull Releases all unmanaged resources associated with the StreamSocket object

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 49: Windows 8 Metro apps and the outside world

Using the StreamSocketListener

bull This class enables listening for an incoming network connection using a TCP stream socket and accepting the connection

bull What you can do with the StreamSocketListenerndash After instantiation of the StreamSocketListener use the Control property to

retrieve a StreamSocketListenerControl object bull Can be used to set the socket quality of service

ndash Assign the ConnectionReceived event to an event handlerndash Call the BindServiceNameAsync or BindEndpointAsync method to bind to a

local TCP port or service namendash After an incoming connection is received use the

StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created

ndash Use the StreamSocket object to send and receive datandash Call the Close method to stop listening for and accepting incoming network

connections bull Releases all unmanaged resources associated with the StreamSocketListener

object

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 50: Windows 8 Metro apps and the outside world

WEBSOCKETS

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 51: Windows 8 Metro apps and the outside world

Whatrsquos a WebSocket

bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverndash To establish a WebSocket connection a specific HTTP-based

handshake is exchanged between the client and the server ndash If successful the application-layer protocol is upgraded

from HTTP to WebSockets using the previously established TCP connection Once this occurs HTTP is completely out of the picturebull Data can be sent or received using the WebSocket protocol by

either endpoint at any time until the WebSocket connection is closed

ndash Only works when the server has a WebSocket

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 52: Windows 8 Metro apps and the outside world

Two types of WebSockets exist

MessageWebSocket StreamWebSocket

Suitable for typical scenarios where messages are not extremely large

Suitable for scenarios in which large files (such as photos or movies) are being transferred

Enables notification that an entire WebSocket message has been received

Allows sections of a message to be read with each read operation

Supports both UTF-8 and binary messages Supports only binary messages

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 53: Windows 8 Metro apps and the outside world

SETTING THE CORRECT CAPABILITIES FOR NETWORK COMMUNICATION

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 54: Windows 8 Metro apps and the outside world

Setting the correct capabilities for network communication

bull When building apps that need accessing services we need to set the correct capabilities

bull Checklistndash Determine the direction of network access needed by the app

bull Outbound client-initiated requests bull Inbound unsolicited requests bull A combination of the two

ndash Determine the type of network resources that that app will communicate withbull Trusted resources on a Home or Work networkbull An app might need to communicate with resources on the Internetbull An app might need access to both types of network resources

ndash Configure the minimum-required networking isolation capabilities in the app manifest

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 55: Windows 8 Metro apps and the outside world

Network capabilities

bull Not all apps require access to the networkndash Only enable the network capabilities for the apps that dondash Windows 8 exposes several types of network access

bull Network access requests are divided into two categoriesndash Outbound client-initiated requests

bull The app acts as the client and initiates network access bull The client app sends one or more requests to the server and the server

sends back a response

ndash Inbound unsolicited requestsbull The app acts as a network server and listens for inbound network requests

from a remote computerbull The remote computer initiates network access by sending an initial request

to the app which acts as serverbull The remote computer sends one or more requests to the app which sends

back one or more responses to the remote computerbull An app that functions as a media server

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 56: Windows 8 Metro apps and the outside world

Networking isolation capabilities

Capability Description

Internet (Client)(internetClient in manifest)

Provides outbound access to the Internet and networks in public places like airports and coffee shop Most apps that require Internet access should use this capability

Internet (Client amp Server)(internetClientServer in manifest)

Gives the app inbound access from the Internet and networks in public places like airports and coffee shops Inbound access to critical ports are always blocked The internetClient capability will still need be declared if outbound connectivity is required

Private Networks (Client amp Server)(privateNetworkClientServer in manifest)

Gives the app inbound and outbound network access at the users trusted places like home and work Inbound access to critical ports are always blocked

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 57: Windows 8 Metro apps and the outside world

Some typical use cases of capabilities

Application Description

A Web client that only consumes content This would include apps that loads HTML from a website and apps that uses RSS syndication or the AtomPub protocol

internetClient

A social network app This includes an app that consumes and produces content on a social network site

internetClient

A peer to peer (p2p) app This includes an app that provide access to instant messenger or chat internetClientServer

An app for sharing in a home or work network This includes an app that accesses media or network attached storage (NAS) content

privateNetworkClientServer

A line of business app at home or work This includes an app that acts as an HTTP client or uses sockets or WebSockets

privateNetworkClientServer

A productivity app with networking features at home or work This includes a productivity app that accesses network features

privateNetworkClientServer

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 58: Windows 8 Metro apps and the outside world

Some typical use cases of capabilities (2) Application Description

A game app that requires network access internetClient

A multiplayer internet game app that does matchmaking internetClient

A multiplayer game app that discovers players with multicast discovery or using multicast internetClientServer

A multiplayer game app that uses the home or work network This includes an app that discovers players with multicast discovery or is discovered using multicast

privateNetworkClientServer

A broadcasting app This includes an app that receives radio broadcasts over the Internet internetClient

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 59: Windows 8 Metro apps and the outside world

Summary

bull Windows 8 supports many types of servicesbull Most common including WCF ASMX oData

work similarly to Silverlightbull Asyncawait pattern makes development

easierbull More complex types including oAuth and

sockets are pretty easy using WinRT APIbull Support for security

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 60: Windows 8 Metro apps and the outside world

THANKS

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)
Page 61: Windows 8 Metro apps and the outside world

Windows 8 Metro apps and the outside worldSILVERLIGHTSHOWNET WEBINARS SERIESGILL CLEEREN 15th August 2012wwwsnowballbe - gillcleerenordinabe - gillcleeren

  • Windows 8 Metro apps and the outside world
  • Agenda
  • Accessing data behind a service
  • Working with services to access data
  • Working with services to access data (2)
  • Working with services
  • WCF and ASMX Services
  • ASMX services (aka good old webservices)
  • Accessing an ASMX service from Windows 8
  • WCF Services
  • WCF Services (2)
  • Things to note when working with WCF (also goes for ASMX)
  • What about security for service communication
  • REST services
  • Parsing the response
  • Credential support with REST services
  • Working with oData services
  • What is oData
  • Sample URIs
  • Navigation
  • Queries
  • oData and WinRT
  • Syndication
  • Syndication in general
  • Syndication in WinRT
  • Authenticating using the WebAuthBroker
  • The WebAuthBroker class
  • The WebAuthBroker class (2)
  • Benefits of the WebAuthBroker
  • How the WebAuthBroker works
  • Using the Live SDK in your Windows 8 apps
  • Live SDK Integration
  • Live SDK Integration (2)
  • To integratehellip
  • Accessing SkyDrive from your apps
  • Using roaming data in your applications
  • Roaming data
  • Roaming data (2)
  • Example of roaming data
  • Example of roaming data (2)
  • Some best practices around roaming data
  • Working with sockets
  • Types of socket communication in WinRT
  • When and when not to use sockets
  • TCP Sockets
  • TCP Sockets (2)
  • TCP Sockets (3)
  • Using the StreamSocket
  • Using the StreamSocketListener
  • WebSockets
  • Whatrsquos a WebSocket
  • Two types of WebSockets exist
  • Setting the correct capabilities for network communication
  • Setting the correct capabilities for network communication (2)
  • Network capabilities
  • Networking isolation capabilities
  • Some typical use cases of capabilities
  • Some typical use cases of capabilities (2)
  • Summary
  • Thanks
  • Windows 8 Metro apps and the outside world (2)