HTML and CSS Reference
Consuming and publishing services
There are two ways for a Windows Store application to deal with contracts—to consume a service and
to publish a service. In terms of coding, the first scenario is far easier to code since it just entails using
a readymade set of Windows 8 components. The second scenario is only a bit harder to code since it
requires that the application complies by the rules set in the definition of the contract.
A to-do list application may implement the Share contract as a source to enable users to share
some of their tasks with friends. The user will invoke the Charms bar and pick up, say, the Mail
application from the Share panel. The Mail application will then receive the content as exposed by the
TodoList application and uses that to prepare an email message.
At the same time, your application may act as the receiver of information that another application
may decide to share. Suppose you have an application that posts to the user's Facebook account.
By making the application implement the Share contract as a target, you enable users of other
applications to send their shared content to yours. So for example users of the TodoList application
can now post their task directly to their Facebook account.
What makes contracts particularly attractive is that Windows Store applications may in the end
result from the composition of functionality picked from different applications. Each application is
then simpler and quicker to write.
Contracts and extensions
In this chapter, you'll go through a few exercises that involve the most commonly used contracts. The
purpose of this section, instead, is to give you a quick overview of the available contracts so that you
know where to look when you need to implement or consume a particular service.
Table 9-1 lists and describes the contracts that Windows Store applications may support. As you can
see, some of the contracts so far referenced under a single name (such as, Share ) are actually available
for coding in two or more flavors (such as, Share source and Share target ).
TABLE 9-1 Contracts available for Windows Store applications
The application implements this contract to share some of its content with any registered
applications that support the Share target contract. Target applications appear in the
Share menu of the Charms bar. For example, the default Weather application in
Windows 8 is enabled to share forecasts.
The application implements this contract to be listed in the Charms bar as an application
which can receive any data the current application can share. For example, the default
Mail application acts as a Share target.
The application implements this contract to expose its own view of files and relevant
folders. This contract entails providing a custom user interface for the user to pick a file
File open/Save picker