共用方式為


Connecting to networks and web services (XAML)

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

In this section, you can learn how to create connected apps. A connected, or network-aware app, can use the network for a variety of purposes including RSS feeds, games, and to interact with nearby devices.

Roadmap: How does this topic relate to others? See:

Topic Description
Adding support for networking

Every Windows Store app is expected to define resource requirements before access is provided. Networked apps should also accommodate the Windows 8 device lifecycle, which includes frequent transitions between different networks and power states. This section supports the following scenarios:

  • Set network capabilities required for Windows Store apps
  • Cache data during network operations
  • Handle network exceptions
  • Manage connections as background tasks to support app lifecycle scenarios
  • Secure and troubleshoot network connections established by your app

Code samples: Background task sample, ControlChannelTrigger HttpClient sample, ControlChannelTrigger HttpClient sample, ControlChannelTrigger with IXMLHTTPRequest2 sample, ControlChannelTrigger TCP socket sample, ControlChannelTrigger StreamWebSocket sample, Lock screen apps sample, Push and periodic notifications client-side sample, Raw notifications sample

Connecting to web services

Connect to HTTP and Representational State Transfer (REST) web services to access, store, or modify content. A web service represents the point at which a user is able to interact with an entity or service that has been made available on the Internet. A few of the many examples of web services include:

  • An online store-front
  • An email service
  • online registration for an event

Code samples: HttpClient Sample, Web authentication sample

Connecting with sockets

Establish socket-based network connections using your Windows Store app. Support is provided for basic TCP and UDP socket connections, as well as UDP multicast, which enables the implementation of other higher-layer networking protocols. This networking feature enables the following network connectivity scenarios:

  • Establish client connections using stream sockets (TCP)
  • Send and receive data with datagram sockets (UDP) including multicast
  • Listen for incoming connections (TCP or UDP) as a server
  • Enable a single device to carry out both client and server operations

Code samples: StreamSocket sample, DatagramSocket sample

Connecting with WebSockets

Use WebSockets for fast, secure bi-directional communication between a client and a server over the web. Data is transferred immediately over a full-duplex single socket connection, allowing messages to be sent and received from both endpoints in real time with low latency. WebSocket connections are great for Windows Store apps that include features such as:

  • Real-time gaming
  • Notifications from social networks
  • Displays of up-to-date information like stock prices or weather conditions

Code samples: Connecting with WebSockets sample

Working with Live services

Enable your Windows Store app to securely sign-in to Live services and exchange data with the popular cloud-based services. Providing Live service functionality in your app allows your user to continue using the services they know, connect with the friends in a manner that’s already familiar, and ensure that these experiences are consistent within your app. Supported Live service functionality includes:

  • Sign in to a Microsoft Outlook.com account and check for new mail.
  • Access or store data to a secure OneDrive account.

Code samples: PhotoSky - OneDrive sample

Connecting to Microsoft Azure Mobile Services

Add a cloud-based backend service to your Windows Store app using Azure Mobile Services. Leveraging these cloud services allows your app development to focus on the front end that your users value, while Mobile Services lets you more easily handle these cloud-based tasks using Microsoft Azure:

  • Storing and querying data using the Mobile Services client library.
  • Authenticating users of your app with Facebook, Twitter, Google, or Microsoft account.
  • Sending push notifications to your app.
  • Enabling periodic notifications to update live tiles.

Code samples: Microsoft Azure Mobile Services samples for Windows Store apps

Connecting with proximity and tapping

Create localized connection and sharing opportunities for Windows 8 on mobile devices. A Windows Store app can use the Proximity APIs to enable two devices that are within close proximity of each other, or physically tapped together, to be aware of one another. Your app can use this awareness to establish a connection between the two devices to:

  • Share content like digital business cards, funny images, or music.
  • Create a multi-player matches for an installed game.
  • Publish or subscribe to messages created on either device.

Code samples: Proximity sample

Connection state and cost management

Create a Windows Store app that efficiently uses network resources and is capable in mobile scenarios that involve a device moving between multiple networks or utilizing networks with associated usage costs. Using these APIs allows a developer to add behavior that demonstrates network awareness in scenarios that have direct impact on the end-user experience:

  • Monitor and optimize general network usage
  • Provide awareness of network availability to support transitions in mobile scenarios
  • Notify the end-user and potentially limit network connectivity when on a metered network

Code samples: Network Information sample, Mobile Broadband Account Provisioning sample

Accessing and managing syndicated content

Create Windows Store apps that consume and syndicate web content using feeds. Protocols supported include the Really Simple Syndication (RSS), Atom Syndication, and the Atom Publishing Protocol. Content syndication activities can include:

  • Retrieving or sharing basic syndicated content feeds
  • Updating a photo-stream on a photo sharing service
  • Viewing complex data collections, like the movie catalog of a movie streaming service.

Additionally, C++ support is provided for JavaScript Objection Notation (JSON). JSON is a data format returned by many popular web services. It is a compact data format that can result in lower latency over constrained connections.

Code samples: Syndication sample, AtomPub sample, Integrating content and controls from web services sample

 

Roadmap for creating Windows Store apps using C# or Visual Basic