Although you’ll usually host your Silverlight
applications in a standard Windows Azure web role, you can host your
Silverlight applications in BLOB storage, if required. Depending on your
web application, you can effectively use BLOB storage to achieve
massive scale for minimal cost. If you run a foreign currency exchange
website, you might want to host the main site (which could offer the
option to purchase currency) in a web role, but host an exchange rate
calculator in BLOB storage.
In this section, we’ll look at
how you can enable such scenarios by showing you how you can do the
following using BLOB storage:
Host a
standalone Silverlight application that’s contained in a static HTML
page
Host a
standalone Silverlight application that’s contained in an ASP.NET web
page
Get
your Silverlight application that’s hosted in BLOB storage to
communicate with external web services
Store
external Silverlight application access files
And now for the details
that will enable you to do all this wonderful stuff with BLOB storage.
1. Hosting the
Silverlight Spectrum emulator
If you’ve
developed a standalone Silverlight application that requires no
interaction with any backend services, BLOB storage is a cost-effective
candidate for hosting your Silverlight application. These types of
applications typically include games, tax calculators, and other
widgets.
For our next example, we’ll
show you how to host a small Silverlight application in BLOB storage.
The application that you’ll host is a Silverlight ZX Spectrum emulator,
which was an 8-bit home computer of the 1980s, very like a Commodore 64
(actually, that’s not true; it was much worse, but it had spirit). Figure 1
shows the emulator running from BLOB storage.
The ZX
Spectrum emulator not only allows you to play games from the 1980s, but
as you can see from figure 1,
you can even write BASIC programs in it. Now, we don’t want you to lose
focus on this book as soon as you load this thing. As cool as Jet Set
Willy is, it won’t help you deliver your amazing cloud-based
application. You’ll have to continue to pay attention to learn how to do
that.
To store the application
in BLOB storage, upload ZXSilverlight.xap using the same procedure you
used in the previous section. (You can download this Silverlight
application and its source code from http://www.azureinaction.com.) You must set the BLOB with the correct MIME type;
otherwise, the browser won’t be able to launch the application. The
MIME type for a Silverlight application is application/x-silverlight-app.
You’re also going to store the
HTML page that hosts the Silverlight application in BLOB storage. The
following listing shows the HTML that runs the ZX Spectrum emulator
Silverlight application (ZXSilverlight.app).
Listing
1. HTML for the ZX Spectrum emulator Silverlight application
By looking at listing 1,
you can see that the HTML page doesn’t have any logic in it. Its job is
to host the Silverlight application. Because this web page is just a
host for a Silverlight application, using a full-fledged web server
would be a little over the top (and expensive); a static HTML page
hosted in BLOB storage will do the job perfectly.
Tip
If you have an existing web
page that you host outside BLOB storage (you’re using a web role or an
existing web hosting provider to host it), you can still host your
Silverlight application in BLOB storage but keep your site with your
existing host. To do so, you need to change the source
parameter of the Silverlight plug-in (see listing 1) to point to your
BLOB storage URI.
This standalone Silverlight
application doesn’t require access to any backend web services, but what
if you want to host an application that does? You can still host your
application in BLOB services, but you’ll need to understand how a
cross-domain policy works.