Microsoft Silverlight 5 and Windows Azure Enterprise Integration

By David Burela
  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Getting Started

About this book

Microsoft Silverlight is a powerful development platform for creating rich media applications and line of business applications for the web and desktop.

Microsoft Windows Azure is a cloud services operating system that serves as the development, service hosting, and service management environment for the Windows Azure platform.

Silverlight allows you to integrate with Windows Azure and create and run Silverlight Enterprise Applications on Windows Azure.

This book shows you how to create and run Silverlight Enterprise Applications on Windows Azure.

Integrating Silverlight and Windows Azure can be difficult without guidance. This book will take you through all the steps to create and run Silverlight Enterprise Applications on the Windows Azure platform. The book starts by providing the steps required to set up the development environment, providing an overview of Azure. The book then dives deep into topics such as hosting Silverlight applications in Azure, using Azure Queues in Silverlight, storing data in Azure table storage from Silverlight, accessing Azure blob storage from Silverlight, relational data with SQL Azure and RIA, and manipulating data with RIA services amongst others.

Publication date:
March 2012
Publisher
Packt
Pages
304
ISBN
9781849683128

 

Chapter 1. Getting Started

This chapter will cover how to configure a development environment that is ready for both Silverlight and Windows Azure development.

While this book assumes a basic knowledge of Silverlight, setting up a development environment to support the Azure development requires a few additional tools and Software Development Kits (SDKs) to be installed.

It is possible to develop Windows Azure applications that are developed entirely on a developer's machine and are never deployed to the Windows Azure servers. To utilize Windows Azure, you will eventually need to deploy your application onto the Windows Azure servers. This chapter will cover how to create an Azure account and deploy directly to it with Visual Studio 2010.

In this chapter, we will discuss the following topics:

  • How to prepare a system for Azure and Silverlight developments

  • Useful tools to assist with the development

  • How to deploy applications onto the Azure platform

Installation

Getting your system ready for the development with Silverlight and Windows Azure can be tricky, as there can be a lot of service packs, tools, SDKs, and SDK toolkits that need to be installed. Microsoft has a page dedicated to getting your system ready for the Silverlight development (http://www.silverlight.net/getstarted/) and another for setting up Windows Azure (http://www.microsoft.com/windowsazure/getstarted/).

As it can be difficult to keep a track of which versions of which tools need to be installed, the recommended setup method is to use the automated Microsoft Web Platform Installer.

Visual Studio 2010

Azure and Silverlight developments can be done with both the free Visual Studio 2010 Express Web Edition (http://www.microsoft.com/express/Web) and the full versions of Visual Studio 2010 (Professional, Premium, and Ultimate). There is a system requirement of IIS 7, which requires that your development machine should be Windows Vista or above (Windows Server 2008, Windows 7, Windows 8, and so on).

This book will assume that the reader is using a full version of Visual Studio 2010, but most features should still be available in both the versions. If the reader does wish to use Visual Studio 2010 Express Web Edition, then it can be installed automatically at the same time with the Microsoft Web Platform Installer.

Web platform installer

Once Visual Studio 2010 has been installed on your computer, the recommended way for installing the required tools and SDKs is with the Microsoft Web Platform Installer (http://www.microsoft.com/web/downloads/). The web platform installer always lists the latest versions of the tools and SDKs, which save your time, trying to track them down. The web platform installer will also download and install any required prerequisites. The steps are as follows:

  1. 1. Download and install the web platform installer from http://www.microsoft.com/web/downloads/.

  2. 2. Open the Microsoft Web Platform Installer from the start menu by clicking on Start | All Programs | Microsoft Web Platform Installer.

  3. 3. In the search window, type Visual Studio 2010 service pack and select the latest service pack. In the following screenshot, Service Pack 1(SP1) was the latest available:

  4. 4. Search for Silverlight 5 and select Silverlight 5 Tools for Visual Studio 2010, as shown in the following screenshot:

  5. 5. Search for RIA Services Toolkit and select the latest version of the WCF RIA Services Toolkit.

  6. 6. Search for Azure and select the latest versions of:

    • Windows Azure SDK for .Net

    • Windows Azure Libraries for .Net

  7. 7. In order to connect to SQL Azure, the 2008 R2 version of SQL Management Studio is required. The free express version is available to be installed. Search for SQL Server Express 2008 R2 and install the following:

    • SQL Server Express 2008 R2 Management Studio Express with SP1

    • SQL Server Express 2008 R2

    Note

    Frequently updated tools

    The tools available to be installed can change frequently. Use the list as a guide to what should be installed on your PC. An easy rule of thumb is to select any option that mentions Silverlight RIA Services or Azure.

  8. 8. Once all the components have been selected and installed, the web platform installer should show those components as Installed and unable to be selected again for installation.

 

Installation


Getting your system ready for the development with Silverlight and Windows Azure can be tricky, as there can be a lot of service packs, tools, SDKs, and SDK toolkits that need to be installed. Microsoft has a page dedicated to getting your system ready for the Silverlight development (http://www.silverlight.net/getstarted/) and another for setting up Windows Azure (http://www.microsoft.com/windowsazure/getstarted/).

As it can be difficult to keep a track of which versions of which tools need to be installed, the recommended setup method is to use the automated Microsoft Web Platform Installer.

Visual Studio 2010

Azure and Silverlight developments can be done with both the free Visual Studio 2010 Express Web Edition (http://www.microsoft.com/express/Web) and the full versions of Visual Studio 2010 (Professional, Premium, and Ultimate). There is a system requirement of IIS 7, which requires that your development machine should be Windows Vista or above (Windows Server 2008, Windows 7, Windows 8, and so on).

This book will assume that the reader is using a full version of Visual Studio 2010, but most features should still be available in both the versions. If the reader does wish to use Visual Studio 2010 Express Web Edition, then it can be installed automatically at the same time with the Microsoft Web Platform Installer.

Web platform installer

Once Visual Studio 2010 has been installed on your computer, the recommended way for installing the required tools and SDKs is with the Microsoft Web Platform Installer (http://www.microsoft.com/web/downloads/). The web platform installer always lists the latest versions of the tools and SDKs, which save your time, trying to track them down. The web platform installer will also download and install any required prerequisites. The steps are as follows:

  1. 1. Download and install the web platform installer from http://www.microsoft.com/web/downloads/.

  2. 2. Open the Microsoft Web Platform Installer from the start menu by clicking on Start | All Programs | Microsoft Web Platform Installer.

  3. 3. In the search window, type Visual Studio 2010 service pack and select the latest service pack. In the following screenshot, Service Pack 1(SP1) was the latest available:

  4. 4. Search for Silverlight 5 and select Silverlight 5 Tools for Visual Studio 2010, as shown in the following screenshot:

  5. 5. Search for RIA Services Toolkit and select the latest version of the WCF RIA Services Toolkit.

  6. 6. Search for Azure and select the latest versions of:

    • Windows Azure SDK for .Net

    • Windows Azure Libraries for .Net

  7. 7. In order to connect to SQL Azure, the 2008 R2 version of SQL Management Studio is required. The free express version is available to be installed. Search for SQL Server Express 2008 R2 and install the following:

    • SQL Server Express 2008 R2 Management Studio Express with SP1

    • SQL Server Express 2008 R2

    Note

    Frequently updated tools

    The tools available to be installed can change frequently. Use the list as a guide to what should be installed on your PC. An easy rule of thumb is to select any option that mentions Silverlight RIA Services or Azure.

  8. 8. Once all the components have been selected and installed, the web platform installer should show those components as Installed and unable to be selected again for installation.

 

Useful tools


There are many tools available to assist you with the development of Silverlight and Windows Azure enterprise applications. The following is a short list of tools that may be useful while progressing through this book.

Official Windows Azure Tools for Visual Studio

The best tool for deploying to and diagnosing Windows Azure is the official Microsoft Azure Tools for Visual Studio. These tools enable you to manage your Windows Azure services while you work with Visual Studio. Some of the functionalities provided are as follows:

  • The ability to deploy directly to Azure from within the Visual Studio

  • IntelliTrace debugging of your deployed instances

  • Azure storage services access through the Visual Studio Server Explorer

The following screenshot shows the Server Explorer being used to browse the contents of the Blob storage. It can be accessed from Visual Studio from the menu bar by selecting View | Server Explorer. New accounts can then be added by right-clicking on the Windows Azure Storage node and selecting Add new storage account:

Azure Storage Explorer

The Windows Azure Tools for Visual Studio provide a basic support for browsing storage accounts to assist with debugging. However, the functionality of the built-in tools can be lacking if you are trying to upload new files or modify the metadata.

The Azure Storage Explorer (http://azurestorageexplorer.codeplex.com) is a GUI tool for viewing and modifying the data in a blob, queue, and table storage within the Windows Azure Storage. The tool is useful for quickly creating folders and uploading files such as media, or for downloading log files for viewing. It is also valuable for debugging the messages waiting to be processed in a queue, or whichever data is present in a table.

The tool is free and open source and is a good first choice when looking for a way to view the contents of your storage accounts. The following screenshot demonstrates the Azure Storage Explorer being used to browse and open an image of a Tulip from the Blob storage:

Expression Blend

If you plan to perform any serious UI work on a Silverlight application, then Expression Blend (http://www.microsoft.com/expression/products/Blend_Overview.aspx) is an essential tool. Expression Blend is a tool for designers to create XAML-based user interfaces. While it is designer focused, anyone who is creating serious Silverlight applications should be using it over the built-in designer tools within Visual Studio 2010. Expression Blend offers a rich experience while designing screens and has a number of useful features, such as design-time data (sample data while designing a screen), or the ability to create keyframe-based animations.

Expression Blend and Visual Studio 2010 integrate well together, both applications have the ability to work simultaneously with the same solution. As Expression Blend works with the same solution files, all the design work can be kept in a source control, side-by-side with the code. The following screenshot shows a Visual Studio 2010 solution that has been opened with Expression Blend. The tabs on the left-hand side are for selecting files within the project, while the tabs on the right-hand side are used for modifying properties of the selected visual elements:

Expression Blend is not a free product and must be purchased in the same way as Visual Studio 2010. If you are in a possession of an MSDN account, then you may find that it is already included in your subscription.

Silverlight Toolkit

Silverlight comes with a basic set of UI controls that can be used to create simple screens for your application. However, most applications will require additional controls. The Silverlight Toolkit (http://silverlight.codeplex.com/) provides a range of extra controls that can be used in your applications for free. These are the basic set of additional controls that your application should be using.

Two controls that are useful for working with data are the Data Grid and Data Grid Pager. Silverlight does not come with controls to display tabled data, making these controls useful for data heavy applications.

The Silverlight Toolkit also gives support for themes, allowing you to change the look and feel of all controls in your application with ease.

Other useful controls available in the toolkit include the following:

  • Charting

    • Bar chart

    • Line chart

    • Pie chart

    • Bubble chart

  • Calendar control / date picker

  • Busy indicator

  • Dock panel

Telerik Silverlight controls

The Silverlight Toolkit is a minimum set of additional controls that all projects should take advantage of, but it is highly recommended that you purchase a commercial control set.

Note

I have personally used a number of different control packs from different vendors, but I consistently come back to using the Telerik controls (http://www.telerik.com/products/silverlight.aspx). Their controls have a wide range of functionality, are updated frequently, and the technical support is exceptional. Any issues I have had with implementing the controls in my applications have been promptly addressed every time.

A short list of the available controls includes:

  • Advanced charting

  • High performance datagrids

  • Sparklines

  • Windows that can be docked and tabbed

The controls can be pricey, but the amounts of time they will save a development team quickly recover the costs.

Silverlight Spy

Silverlight Spy (http://firstfloorsoftware.com/silverlightspy/) is a runtime inspection tool useful for debugging Silverlight applications. Silverlight Spy allows you to explore the visual hierarchy of your screens at runtime, which can assist when you are trying to discover why a control is missing a border, or is on the wrong side of the screen.

There are many other functions that the tool allows, such as the ability to inspect the isolated storage of the application, real-time performance metrics of your Silverlight application, and event monitor for watching in real time as events are raised.

The application is not free, but it may be worth the purchase if you find yourself in a tricky debugging situation.

LINQPad

LINQPad (http://www.linqpad.net/) acts as a scratchpad that allows you to quickly compile and execute short snippets of C#, VB.Net, or F# code. It may not have any direct impact on your Azure development, but it is a useful tool to be stored in your collection.

The main use of LINQPad is to quickly write and execute LINQ statements against data sources. This quick execution cycle allows you to tweak and modify your LINQ queries quicker than trying to recompile and execute an entire application.

The power of LINQPad is its ability to query against a variety of data sources directly. A few of the supported sources include:

  • LINQ to SQL (SQL Server)

  • LINQ to XML

  • SQL Azure

  • Azure tables

  • OData endpoints

  • WCF data services endpoints

The ability to query against OData endpoints directly can help develop applications against data from other sources. The following screenshot demonstrates the ability to query against the Netflix endpoint at http://odata.netflix.com/v1/Catalog/. Using LINQPad, you are able to construct a standard LINQ query to retrieve all movie titles that were released in the year 1990 and have an average rating over three stars:

 

Creating a Windows Azure account


Signing up for a Windows Azure account is a relatively easy process. Go to http://azure.com/ and click on Sign up to begin the sign up process.

Windows Azure is a consumption-based hosting service that requires you to pay for the resources that you consume. Microsoft charges for the usage of each distinct service that they offer, based on the consumption of that individual resource or service, for example, CPU hours, Internet bandwidth, storage, AppFabric, or SQL Azure. The various components of Windows Azure will be explored further in Chapter 2,Introduction to Windows Azure.

Microsoft has many promotional offers that give you a certain amount of resources free each month to assist with the adoption and development of your Azure application. If you have any sort of agreement or subscription with Microsoft (such as a MSDN, BizSpark, DreamSpark subscription, or are part of the Microsoft Partner Network), it may be worth checking whether you are eligible for any free trials.

You will be shown a number of different account types. They all differ by cost and what base resources you will get each month. Anything exceeding those quotas will be charged, based on consumption.

Once an account has been created and billing has been sorted out, then you are past the difficult stage and can move onto deploying an application onto your new service.

Note

Watch your consumption carefully during development

During development, it is easy to deploy your application onto the servers to see it running in the cloud. It is also easy to forget that you deployed your application and had it configured for a high number of computer instances. If you go over your monthly allocation of the free usage, Microsoft will charge you. This has happened to me on more than one occasion, and finding the bill on your credit card is never a good feeling. Set a calendar reminder for Friday afternoons to check that your deployments have been pulled down, before you go home for the weekend, to avoid this.

 

Deploying to Windows Azure from Visual Studio 2010


In order to be able to deploy a Windows Azure application onto the Windows Azure servers, you will be required to create an hosted service that will host and execute your code and a storage account that will hold the packaged Azure application before the deployment. Deploying an Azure application onto the hosted service from Visual Studio 2010 will require setting up certificates.

The next section will explain the entire process of deployment end-to-end. Later chapters in the book will describe how to run and debug applications on the local developer machine.

Creating the hosting service

In order to create the hosting service, you will need to complete the following steps:

  1. 1. Log on to the Windows Azure Management Portal at https://windows.azure.com.

  2. 2. Go to the Hosted Services, Storage Accounts & CDN section and click on Create a New Hosted Service.

  3. 3. Give the hosted service a friendly name for you to keep track of and also a suitable URL prefix. The URL prefix is public, so it must be globally unique. In this example, the complete URL https://packtdemoapp.cloudapp.net has been used.

  4. 4. Select the option to Create a New Affinity Group. On the next screen, when asked about the location where your services should be hosted, select one that is close to your physical location. For this example, South Central US has been selected. Creating a new affinity group allows you to group your services together at the same physical location. This is useful for making sure that the servers hosting and executing the Azure application are in the same data center as the storage accounts:

    Note

    Affinity groups

    Ensure that while deploying an Azure application, the hosted service and the storage account are hosted in the same data center by using affinity groups. Having your services hosted in different data centers can cause a lot of latency in your application, as well as potentially cause you to be charged with bandwidth costs between data centers.

    Just selecting a location for your service, without setting an affinity group does not guarantee that your services will be in the same data center in that location. Confirm that the affinity group is set on your services to avoid this.

  5. 5. If you had an Azure application already packaged, you could select to immediately upload and deploy the application on this screen. In this example, we are deploying to Azure directly from Visual Studio 2010, so select Do not deploy.

  6. 6. Click on OK to create the hosted service, which will be ready for us to deploy an Azure application, as shown in the following screenshot:

Creating the storage account

When the Windows Azure Management Portal is used to deploy your Azure application, you can directly upload your packaged Azure application onto the Azure servers. However, when deploying from Visual Studio 2010, the packaged application needs to be stored in the Azure Storage, so that it can be deployed onto the Azure servers from there.

Instead of the Windows Azure Management Portal, create a storage account and again give it a suitable endpoint name. The following screenshot shows an endpoint being created within the South Central US affinity group with the endpoint name packtdemo:

Deploying applications onto Azure servers

In order to be able to deploy an application onto Azure servers, you will first need an application to deploy. Next, you will create a new Azure project that will be used as our example:

  1. 1. Open Visual Studio 2010, create a new Windows Azure Project, and give the project a suitable name, such as PacktAzureDeploymentDemo, as shown in the following screenshot:

  2. 2. Add a single ASP.NET Web Role into the project. An Azure solution with a single web role added to it can be seen in the following screenshot. Other roles are visible and selectable, but this exercise will only be utilizing the web role:

  3. 3. Visual Studio will create the solution with two projects as can be seen in the following screenshot. The first project PacktAzureDeploymentDemo is the Azure project that defines the metadata for all of the roles and instances that will be created when deployed onto Azure servers. The second project WebRole1 is a standard ASP.Net project, where all the logic of your project will reside:

  4. 4. Once the project has been created, feel free to modify the Default.aspx file in WebRole1 slightly, by adding your own name to the header similar to what is shown in the following screenshot. In this way, once the application is deployed, you can see that it is indeed your application:

The project is now ready to be deployed onto the Azure servers.

Creating certificates to authenticate deployment

In order to allow Visual Studio 2010 to communicate with the Windows Azure deployment API, management certificates are required to authenticate the requests. Visual Studio has a wizard that helps with the creation and uploading of the required certificates:

  1. 1. With your Azure solution still open, right-click on the Azure project (not the ASP.Net project) and select Publish, as shown in the following screenshot:

  2. 2. This will bring up a new Publish Windows Azure Application dialog box as shown in the following screenshot. If you had previously configured your credentials, you could select them here. As this is the first time you are opening this dialog box, you will be required to configure your credentials. Click on Sign in to download credentials to begin the process:

  3. 3. A web browser will be opened and request that you sign into your Azure account. Once you have signed in, you will be prompted by the browser to download the credential file.

  4. 4. Once the credential file has been downloaded, you can return to Visual Studio 2010 and import the file.

  5. 5. Once your credentials have been configured, you will now be able to select the hosted service and environment to deploy your application (production or staging). More details about the different deployment environments will be discussed in later chapters. A deployment to production has been chosen in the following screenshot:

  6. 6. Click on Publish and Visual Studio 2010 will begin the process of deploying your application. The following screenshot shows the starting of the deployment process. The Visual Studio packages the project, connects to the Azure servers, and then uploads the package:

  7. 7. The deployment process has been completed in the following screenshot. The package was successfully uploaded and the web role was initialized and brought online, ready to service user requests. Be aware that the first deployment to your instances can take a long time, sometimes up to 15 minutes before they are fully running. There are ways to shorten the deployment time during the development by using web deployment after the initial deployment:

    Note

    Web deployment

    To shorten the development cycle, it is possible to use web deployment to update an existing deployment. You can only have a single compute instance running and the changes made are only temporary until the compute instance restarts. This is a development enhancer and should never be used on a production deployment. More details about this feature can be found on the Windows Azure Tools blog at the following URL:

    http://blogs.msdn.com/b/cloud/archive/2011/04/19/enabling-web-deploy-for-windows-azure-web-roles-with-visual-studio.aspx

  8. 8. Once Visual Studio 2010 has completed the deployment and the servers have reported back that the service has started successfully, you will finally be able to view your application.

  9. 9. Click on the website URL in the Windows Azure Activity Log window to browse to the site, this will be the URL you configured when creating the hosted service. If all goes well, you should see your website running with your modifications, similar to the following screenshot:

  10. 10. Remember to remove your deployment when you are finished, so that you are not charged for it. You can do this through the Azure Management Portal. You can also do it quickly from within the Visual Studio by right-clicking on Deployment in the Windows Azure Activity Log window and selecting Delete.

 

Summary


You have now seen how to prepare your system for development with Silverlight and Windows Azure. Previously, setting up a machine could be difficult, but it has been made simpler with the release of the Microsoft Web Platform Installer.

There are also a wide range of tools that can be utilized to assist the development of applications. Explore the options available to you and see what helps to speed your own development times.

In the next chapter, a more detailed introduction to the Windows Azure Platform will be provided.

About the Author

  • David Burela

    David Burela works full time as a senior .Net consultant for an Australian consulting firm. At university, he did a Bachelor of Computer Science, a Masters of Computer Science and a Masters of Business Administration (MBA). He uses this unique mixture of technical and business skills to help the clients he consults for. David loves researching the latest cutting edge technologies and frameworks and is heavily invested in Windows Azure, Silverlight and Windows Phone 7. This passion for researching and learning sees him helping out with the developer community. He ran a local .Net user group for 3 years and currently runs the Melbourne Silverlight user group. While running user groups is enjoyable, presenting at them is more fun. He keeps his presentation skills sharp by delivering talks every few months on a variety of topics. David has been recognized for his abilities and contributions with numerous awards. In 2007, David was recognized for his contributions to the community and was a state finalist for the Australian government's "Young Australian of the Year" award. In 2008 David entered into a global programming competition run by Microsoft and competed against winning teams from over 80 different countries. David and his team won the global competition with their cloud based agriculture system that would assist farmers and growers in drought stricken regions. In 2010, David entered into another Microsoft programming competition, this time for Windows Phone 7, and was runner up for his submission. The phone application told residents in Sydney Australia if it was safe to swim at the local beaches that day.

    Browse publications by this author
Book Title
Access this book, plus 7,500 other titles for FREE
Access now