windows 8 apps and the outside world
TRANSCRIPT
Windows 8 apps and the outside world
Gill CleerenMicrosoft Regional Director amp MVPTelerik MVP
About myself
bull Gill Cleerenbull NET Architect Ordina (wwwordinabe) bull Microsoft Regional Directorbull Silverlight MVPbull Speaker (TechDays TechEd DevReach DevDays NDC Norway
Telerik Usergroup tours)bull Visug user group lead (wwwvisugbe)bull Author
bull Silverlight 4 Data and services cookbookbull Silverlight 5 Data and services cookbook
bull Blog wwwsnowballbebull Email gillsnowballbe bull Twitter gillcleeren
Silverlight 5 Data and Services Cookbook available
bull Updated for Silverlight 5bull Over 115 recipes (thatrsquos 30 extra)bull Extended to about 700 pages bull (Thatrsquos 250 extra)
bull Covering WP7 MVVM RIA Services and much morebull More info
httpbitlySL5DataAndServices
Agenda
bull Accessing data behind a servicebull Working with WCF and ASMX servicesbull Working with REST servicesbull Accessing oData servicesbull Syndication with RSSbull Background transfersbull Tiles interactions
bull Periodic tile updatesbull Push notifications
bull 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
bull TCP socketsbull WebSockets
What we arenrsquot covering today
bull ControlChannelTriggerbull Raw notificationsbull Azure
Accessing data behind a service
Working with services to access data
bull Service communication is always done asynchronousbull In Silverlight this was done using a callbackbull In C5 we got the asyncawait keywords
bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread
bull Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)
bull Getting data in a Metro application is a 3-step processbull Calling the service asynchronousbull Receiving and parsing the databull Using the data for example in a data-binding scenario
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
About myself
bull Gill Cleerenbull NET Architect Ordina (wwwordinabe) bull Microsoft Regional Directorbull Silverlight MVPbull Speaker (TechDays TechEd DevReach DevDays NDC Norway
Telerik Usergroup tours)bull Visug user group lead (wwwvisugbe)bull Author
bull Silverlight 4 Data and services cookbookbull Silverlight 5 Data and services cookbook
bull Blog wwwsnowballbebull Email gillsnowballbe bull Twitter gillcleeren
Silverlight 5 Data and Services Cookbook available
bull Updated for Silverlight 5bull Over 115 recipes (thatrsquos 30 extra)bull Extended to about 700 pages bull (Thatrsquos 250 extra)
bull Covering WP7 MVVM RIA Services and much morebull More info
httpbitlySL5DataAndServices
Agenda
bull Accessing data behind a servicebull Working with WCF and ASMX servicesbull Working with REST servicesbull Accessing oData servicesbull Syndication with RSSbull Background transfersbull Tiles interactions
bull Periodic tile updatesbull Push notifications
bull 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
bull TCP socketsbull WebSockets
What we arenrsquot covering today
bull ControlChannelTriggerbull Raw notificationsbull Azure
Accessing data behind a service
Working with services to access data
bull Service communication is always done asynchronousbull In Silverlight this was done using a callbackbull In C5 we got the asyncawait keywords
bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread
bull Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)
bull Getting data in a Metro application is a 3-step processbull Calling the service asynchronousbull Receiving and parsing the databull Using the data for example in a data-binding scenario
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Silverlight 5 Data and Services Cookbook available
bull Updated for Silverlight 5bull Over 115 recipes (thatrsquos 30 extra)bull Extended to about 700 pages bull (Thatrsquos 250 extra)
bull Covering WP7 MVVM RIA Services and much morebull More info
httpbitlySL5DataAndServices
Agenda
bull Accessing data behind a servicebull Working with WCF and ASMX servicesbull Working with REST servicesbull Accessing oData servicesbull Syndication with RSSbull Background transfersbull Tiles interactions
bull Periodic tile updatesbull Push notifications
bull 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
bull TCP socketsbull WebSockets
What we arenrsquot covering today
bull ControlChannelTriggerbull Raw notificationsbull Azure
Accessing data behind a service
Working with services to access data
bull Service communication is always done asynchronousbull In Silverlight this was done using a callbackbull In C5 we got the asyncawait keywords
bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread
bull Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)
bull Getting data in a Metro application is a 3-step processbull Calling the service asynchronousbull Receiving and parsing the databull Using the data for example in a data-binding scenario
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 Background transfersbull Tiles interactions
bull Periodic tile updatesbull Push notifications
bull 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
bull TCP socketsbull WebSockets
What we arenrsquot covering today
bull ControlChannelTriggerbull Raw notificationsbull Azure
Accessing data behind a service
Working with services to access data
bull Service communication is always done asynchronousbull In Silverlight this was done using a callbackbull In C5 we got the asyncawait keywords
bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread
bull Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)
bull Getting data in a Metro application is a 3-step processbull Calling the service asynchronousbull Receiving and parsing the databull Using the data for example in a data-binding scenario
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
What we arenrsquot covering today
bull ControlChannelTriggerbull Raw notificationsbull Azure
Accessing data behind a service
Working with services to access data
bull Service communication is always done asynchronousbull In Silverlight this was done using a callbackbull In C5 we got the asyncawait keywords
bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread
bull Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)
bull Getting data in a Metro application is a 3-step processbull Calling the service asynchronousbull Receiving and parsing the databull Using the data for example in a data-binding scenario
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 asynchronousbull In Silverlight this was done using a callbackbull In C5 we got the asyncawait keywords
bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread
bull Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)
bull Getting data in a Metro application is a 3-step processbull Calling the service asynchronousbull Receiving and parsing the databull Using the data for example in a data-binding scenario
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Working with services to access data
bull Service communication is always done asynchronousbull In Silverlight this was done using a callbackbull In C5 we got the asyncawait keywords
bull Fully supported in MetroWinRT developmentbull await keyword makes things easierbull Doesnrsquot block UI thread
bull Doesnrsquot require the ugly DispatcherBeginInvoke(() =gt hellip)
bull Getting data in a Metro application is a 3-step processbull Calling the service asynchronousbull Receiving and parsing the databull Using the data for example in a data-binding scenario
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Working with services to access data
bull Working with services is preferred in most casesbull Relational databases should be behind a servicebull Local app storage
bull 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 servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Working with services
bull Windows 8 supports all kinds of servicesbull ASMXbull WCFbull REST (JSON or XML)bull RSS (later in this talk)bull Sockets (much later in this talk)bull oData services (you get the drill itrsquos also further in this
talkhellip)bull No WCF RIA Services support out-of-the-box though (so
yes that is NOT in this talk )bull 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 servicebull Add service referencebull Generates proxy
bull All Task-based
bull Use proxy-class with the asyncawait keywords
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Accessing an ASMX service from Windows 8DEMO
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
WCF Services
bull What is supportedbull Bindings
bull BasicHttpBindingbull NetTcpBindingbull NetHttpBindingbull CustomBinding
bull Binding elements bull BinaryMessageEncodingBindingElementbull TextMessageEncodingBindingElement bull ConnectionOrientedTransportBindingElement bull SslStreamSecurityBindingElementbull WindowsStreamSecurityBindingElementbull TcpTransportBindingElementbull Http(s)TransportBindingElementbull TransportSecurityBindingElement
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
WCF Services
bull What is supportedbull Encoding
bull Text Binary
bull Security modesbull None Transport TransportWithMessageCredential TransportCredentialOnly (for
BasicHttpBinding)
bull ClientCredentialTypebull None Basic Digest Negotiate Ntlm Windows
bull Transfer Modebull Buffered Streamed StreamedRequest and StreamedResponse
bull Serializersbull DataContractSerializer DataContractJsonSerializer XmlSerializer
bull Miscellaneousbull ChannelFactorybull DuplexChannelFactory bull CallbackBehavior
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Things to note when working with WCF (also goes for ASMX)
bull No XML config file codebull Code gets generated in the Referencecs file
bull No config edit possible
bull Use the partial ConfigureEndpoint method
bull Only Task-based methods are availablebull Ensures there are no blocking callsbull Is done by default
bull Specify Internet capability
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Accessing a WCF service from Windows 8DEMO
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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 bull Allows safe passing of usernamepassword to service
endpoint
resultSecurityMode = SystemServiceModelBasicHttpSecurityModeTransportCredentialOnly
resultSecurityTransportClientCredentialType = SystemServiceModelHttpClientCredentialTypeWindows
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Secure communication from a Windows 8 appDEMO
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Working with REST services
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
REST services
bull No more WebClient replaced with HttpClientbull Works with asyncbull Located in SystemNet
bull HttpClient definesbull Get(Async)
bull Returns an HttpResponseMessage
bull Put(Async)bull Post(Async)bull Delete(Async) RESTful
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Parsing the response
bull XMLbull Linq-To-XMLbull XmlReaderXmlWriterbull XmlSerializer
bull JSONbull Use the JsonObject and feed it the returned string
bull We can use the Parse() methodbull Throws error if the returned string is faulty or invalid
bull Also defines GetNamedString() GetNamedNumber()bull Parsing via indexer
bull Not recommended
bull DataContractJsonSerializer is also available
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Searching on Flickr using the HttpClient classDEMO
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Credential support with REST services
bull If REST service requires authentication WinRT will support itbull 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()
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Secure REST communicationDEMO
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Working with oData services
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
What is oData
bull Open Data Protocolbull Design goals
bull Invent as little as possiblebull Very low barrier of entry
bull OData is a RESTful protocolbull Builds on HTTP and AtomPubbull Defines
bull XML + JSON data representationbull Addressing schemebull Query operatorsbull Metadata
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Sample URIs
bull httpodatanetflixcomCatalogbull AtomPub service document list of all collections
bull httpodatanetflixcomCatalogGenresbull all entries of a collection
bull httpCatalogGenres(Adventures)bull one entry by PK
bull httpCatalogGenres(Adventures)Name bull one property as XML
bull httpCatalogGenres(Adventures)Name$valuebull only the value
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Navigation
bull httpCatalogGenres(Adventures)Titlesbull related entities
bull httpCatalogGenres(Adventures)$linksTitlesbull only the links
bull httpCatalogGenres(Adventures)Titles$countbull count
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Queries
bull Titles$filter=AverageRating gt 4bull filters
bull Titles$orderby=AverageRating desc ReleaseYear ascbull sorting
bull Titles$select=ShortName ReleaseYearbull projection
bull Paging support $top $skip $skiptoken $inlinecount
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
oData and WinRT
bull Therersquos an OData client library availablebull Requires servers that comply with oData v1-v3bull Support for Add Reference since RCbull Previously we had to use the DataSvcUtil tool to
generate the proxybull Still works if you want complete control over the proxy
generation
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Working with oData servicesDEMO
Syndication
Syndication in general
bull Real Simple Syndicationbull RSS feeds expose information from sites mostly through XMLbull Feed is a list of syndication entries
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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
bull Postbull Authorbull Databull Linksbull Fixed set of elements
bull Parsing it is possible bull Manually (if you like to hurt yourselfhellip)bull Through a third-party library
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Syndication in WinRT
bull WinRT has the WindowsWebSyndication namespacebull Contains SyndicationFeed and SyndicationClient classesbull Allows downloading feed asynchronouslybull Can be provided with credentials if source requires thembull Supports
bull Atom 03 and 10bull RSS 091 092 10 and 20)
bull Returns items in an object modelbull Async (Task-based)
var client = new SyndicationClient() SyndicationFeed feed = await clientRetrieveFeedAsync(ldquoltMy RSS Feedgtrdquo)
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
SyndicationDEMO
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Background transfers
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Background transfers
bull Just like Windows Phone 7 only 1 app can be the main appbull Can be annoying if your app downloads filesbull User canrsquot switch away or the download is interrupted
bull WindowsNetworkingBackgroundTransfer has a BackgroundDownloaderbull Creates DownloadOperation instances
bull Can be paused resumed
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Background transfers
bull Support forbull Credentialsbull Custom headers via SetRequestHeader
bull Use for authentication methods such as cookies forms-based authentication
bull Progress reporting
bull Managed through separate process BackgroundTransferHostexebull Keeps running in the background
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Background transfersDEMO
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Tiles interactions
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodic updates
bull Push notifications
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Periodic tile updates
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Periodic tile updates
bull Poor manrsquos live tilesbull Require nothing more than a service that returns
XML of a tilebadge updatebull Great for distributing updates with wide audience
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Periodic tile updates
bull Setting it upbull Build a service that returns an XML stringbull Build a Metro app that calls the service and sets up periodic
tilebadge updatesbull TileUpdaterStartPeriodicUpdate should be called with every start of
the applicationbull Service should update after about the same amount of time polling
happensbull If service is not available Windows will retry only at the next intervalbull Service can be http or httpsbull App must declare internet capability
bull No support for tile update queueingbull Donrsquot use it for breaking news
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Periodic TilesDEMO
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Push Notifications
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Types of notifications
bull Local (from the app code)bull Can only be used when the app is runningbull Useful for tile updates (not that useful for toasts)
bull Scheduledbull Update at specific timebull Useful for tiles and toasts
bull Periodicbull Update at specific intervalbull Poll a cloud service for content
bull Push notifications are the missing link
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Push notifications over WNS
bull WNS = Windows Notification Servicebull Allows delivery of tile and toast XML messages over the
wirebull Can arrive when the app isnrsquot runningbull Create background processing without processing
bull Happens on the server
bull Transparent process for the developerbull Free services
bull Cloud-based so no worries on scalabilitybull Easily updates millions of devicesbull Register your app for now via httpsmanagedevlivecombuild
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
WNS architecture
Windows 8 Cloud Service
Windows Notification
Service
Metro Style App
NotificationClient
Platform
2
3
1 3
1 Request Channel URI2 Register with your Cloud Service3 Authenticate amp Push Notification
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Push notifications using Azure
bull What we needbull Secure web based API for channel URI registrationbull Persistent storage of channel URIbull Storage for tile and toast images
bull What Azure offers usbull Windows Azure Compute
bull Web Rolebull Full IIS support bull WCF REST and ASPNET MVC
bull Windows Azure Storagebull Table Storagebull Blob Storage
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Push notificationsDEMO
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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 Oauthbull When an app calls the web authentication broker the
user gets a dialog box in which the necessary webpages are rendered to sign inbull 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 appbull User credentials that are isolated from the appbull Native support for single sign-on with online
providersbull Twitterbull Facebookbull Flickrbull hellip
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
How the WebAuthBroker works
bull The web authentication broker is the facilitator between your app and authenticationbull It consists of a set of APIs a broker and a web host
bull Your app uses the APIs to communicate with the broker bull The broker creates a new web host process in a separate app
containerbull The broker communicates with the app assembles the UI and
controls the lifecycle of the web authentication hostbull The web authentication host renders the pages from the online
providers website
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Authenticating using the WebAuthBrokerDEMO
Using the Live SDK in your Windows 8 apps
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Live SDK Integration
bull Using the Live SDK we can from WinRT appsbull Leverage SSO functionalitybull Access data in SkyDrivebull 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
bull httpmanagedevlivecombuild bull Only need the package name
bull Requires that you are signed in with a Live IDMicrosoft accountbull We can log in using a live account or a local accountbull Itrsquos possible to switch between the two
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Live SDK Integration
bull The device has to be trusted bull 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 bull A scope grants a permission levelbull Can be
bull wlsignin bull Single sign-in behavior
bull wlbasicbull Read access to a users basic profile info Also enables read access to a users list of
contactsbull wlcontacts_create
bull Creation of new contacts in the users address bookbull wlcalendars_update
bull Read access to a users personal preferred and business email addressesbull 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 bull 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 accountbull Apps can benefit from this as well using Live SDKbull User needs to grant permission though (once)
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Using the Live SDK in your Windows 8 appsDEMO
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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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
experiencebull Configure once use everywhere
bull Roaming application data makes creating this for us very easybull App data can be local roaming or temporarybull 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 databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Roaming data
bull What to place in roaming databull 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 databull Data that can be readshared with other appsbull Documents pictures exported databull Data that should be exported to SkyDrive
bull Limit is currently 100kbull Preserve battery and performancebull Can be checked using the RoamingStorageQuota classbull 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 classbull 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 timebull Last save wins
bull Write often-changing only every now and thenbull Donrsquot use it to constantly write the location within a songbull Writing too often can result in the device being locked-
out for a certain amount of time
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Using roaming data in your applicationsDEMO
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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
TCP Sockets
bull TCP and UDP can be used to send and receive data in WinRT appsbull Based on classes from the WindowsNetworkingSockets
namespacebull StreamSocketbull StreamSocketListenerbull DatagramSocket
bull Support forbull Making client connectionsbull Listening for connections bull Operating as a server or for both client and server operations
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
TCP Sockets
bull Steps to get TCP sockets working in your Metro appbull Use the StreamSocket class to create a TCP socketbull ConnectAsync on the StreamSocket class allows making a
network connection to a TCP network serverbull StreamsDataWriter allows sending data to the server
bull Basically allows writing common types on a stream
bull 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 serverbull 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 StreamSocketbull 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
bull Use one of the ConnectAsync methods to establish a connection with the remote endpointbull Can be configured for use with SSL
bull Get the OutputStream property to write data to the remote hostbull Get the InputStream property to read data from the remote hostbull Read and write data as neededbull 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 StreamSocketListenerbull 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
bull Assign the ConnectionReceived event to an event handlerbull Call the BindServiceNameAsync or BindEndpointAsync method to bind
to a local TCP port or service namebull After an incoming connection is received use the
StreamSocketListenerConnectionReceivedEventArgs object to retrieve the Socket property with the StreamSocket object created
bull Use the StreamSocket object to send and receive databull Call the Close method to stop listening for and accepting incoming
network connections bull Releases all unmanaged resources associated with the StreamSocketListener
object
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
TCP SocketsDEMO
WebSockets
Whatrsquos a WebSocket
bull The WebSocket Protocol defines a mechanism for two-way communication between a client and a serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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 serverbull To establish a WebSocket connection a specific HTTP-
based handshake is exchanged between the client and the server bull 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
bull 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Using WebSockets from a Metro style applicationDEMO
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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- 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
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
QampA
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Thanks
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-
Windows 8 Metro apps
and the outside worldGill Cleeren
Microsoft Regional Director amp MVPTelerik MVP
- Windows 8 apps and the outside world
- About myself
- Silverlight 5 Data and Services Cookbook available
- Agenda
- What we arenrsquot covering today
- 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)
- Accessing a WCF service from Windows 8
- What about security for service communication
- Secure communication from a Windows 8 app
- Working with REST services
- REST services
- Parsing the response
- Searching on Flickr using the HttpClient class
- Credential support with REST services
- Secure REST communication
- Working with oData services
- What is oData
- Sample URIs
- Navigation
- Queries
- oData and WinRT
- Working with oData services (2)
- Syndication
- Syndication in general
- Syndication in WinRT
- Syndication (2)
- Background transfers
- Background transfers (2)
- Background transfers (3)
- Background transfers (4)
- Tiles interactions
- Types of notifications
- Periodic tile updates
- Periodic tile updates (2)
- Periodic tile updates (3)
- Periodic Tiles
- Push Notifications
- Types of notifications (2)
- Push notifications over WNS
- WNS architecture
- Push notifications using Azure
- Push notifications
- Authenticating using the WebAuthBroker
- The WebAuthBroker class
- The WebAuthBroker class (2)
- Benefits of the WebAuthBroker
- How the WebAuthBroker works
- Authenticating using the WebAuthBroker (2)
- Using the Live SDK in your Windows 8 apps
- Live SDK Integration
- Live SDK Integration (2)
- To integratehellip
- Accessing SkyDrive from your apps
- Using the Live SDK in your Windows 8 apps (2)
- 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
- Using roaming data in your applications (2)
- 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
- TCP Sockets (4)
- WebSockets
- Whatrsquos a WebSocket
- Two types of WebSockets exist
- Using WebSockets from a Metro style application
- Summary
- QampA
- Thanks
- Windows 8 Metro apps and the outside world
-