Home > DeveloperSection > Articles > Install and Create a Windows Azure Application in VS 2010

Install and Create a Windows Azure Application in VS 2010


Cloud Computing Cloud Computing 
Ratings:
0 Comment(s)
 3647  View(s)
Rate this:

Install and Create a Windows Azure Application in VS 2010

To install the Windows Azure Tools, on the menu bar, choose File – New – Project. From Installed Templates choose either the Visual Basic or Visual C# node, and then choose the Cloud node that contains a project template named Enable Windows Azure Tools.

To download the tools, choose the OK button.
After the successful installation A Windows Azure Project tab is displays instead of Enable Windows Azure Tools.

A windows azure application consists of roles that perform the actions required by the application. When you publish your application to Windows Azure, each role is run on a virtual machine in the cloud.

Create a Windows Azure Application:

·         Start Visual Studio 2010 as an administrator.

·         To create a Windows Azure project, on the menu bar, choose FileNewProject.

·         Choose the Cloud template from the Installed template.

·         Choose Windows Azure project and enter the name of the project.

·         Click OK.

Install and Create a Windows Azure Application in VS 2010

·         To add a web role to the solution, choose ASP.NET Web Role and then choose the right arrow. You can add multiple web and worker roles to your Windows Azure solution.
The roles are displayed in the Windows Azure solution pane of the dialog box.

·         Click OK.

Install and Create a Windows Azure Application in VS 2010

You now have a solution with the following two projects:

·         A Windows Azure project

·         A Web role that is an ASP.NET web application

       The Solution explorer view will look similar to the following illustration:

Install and Create a Windows Azure Application in VS 2010

Now to add the code in the Web role project

·         Open Default.aspx file and choose View Designer from the context menu.

·         Open toolbox (Ctrl + Alt + X) and add a new button in the form.

·         To add a click handler for the button, double click the button that you added in the page.

·         Add the namespaces given below:

            using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.Diagnostics;

using Microsoft.WindowsAzure.ServiceRuntime;

 

·         On the click of the button add the following code given below:

     // Setup the connection to Windows Azure Storage

            var storageAccount =  CloudStorageAccount.Parse (
                                  RoleEnvironment.GetConfigurationSettingValue
                                  ("MyConnectionString"));

            var blobClient = storageAccount.CreateCloudBlobClient();

 

            // Get and create the container

            var blobContainer = blobClient.GetContainerReference("quicklap");

            blobContainer.CreateIfNotExist();

 

            // upload a text blob

            var blob = blobContainer.GetBlobReference(Guid.NewGuid().ToString());

            blob.UploadText("Hello Windows Azure");

 

            // log a message that can be viewed in the diagnostics tables called          
             WADLogsTable

            System.Diagnostics.Trace.WriteLine("Added blob to Windows Azure Storage");

 

The above accomplish the tasks given below:

·         Create a CloudStorageAccount instance from a connection string in the configuration settings

·         Create a blob container

·         Upload a text blob to that container

·         Add a diagnostics message for a web role

Add code to set up the diagnostics monitor to transfer the logs every second and start the monitor. The diagnostics monitor uses a connection string that is added when you create the Windows Azure project. The following code must be added at the beginning of the OnStart method in WebRole.cs:

DiagnosticMonitorConfiguration diagObj = DiagnosticMonitor.GetDefaultInitialConfiguration();

 

//Set the service to transfer logs every second to the storage account

diagObj.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(1);

 

//Start Diagnostics Monitor with the new storage account configuration            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagObj);

 

Build and Debug your application

1.      To build the project, open the shortcut menu for the Windows Azure project and then choose Build.

2.      To see the build output, open the shortcut menu for the Windows Azure project and then choose Open Folder in Windows Explorer. Go to the bin\debug directory to view the build output.

3.      To modify settings, choose a role under the Roles node for your Windows Azure project in Solution Explorer, open the shortcut menu for the role and choose Properties.

This will display the property pages for the web role. Every role-level element and attribute in the service definition and service configuration files can be edited using the property pages.

Install and Create a Windows Azure Application in VS 2010

1.      To configure Visual Studio to use the local storage emulator when you run or debug your Windows Azure application, you must add the connection string that you used in the button click event handler. Use the following steps to do this:

a.      On the Settings tab choose the Add Setting button.

b.      In the Name text box, type MyConnectionString.

c.       In the Type combo box, choose Connection String.

d.      Choose the ellipsis in the Value text box. The Storage Account Connection String dialog box is displayed. Choose Use the Windows Azure storage emulator and then choose the OK button.

e.      On the toolbar, choose the Save icon.

Install and Create a Windows Azure Application in VS 2010

To Debug the Windows Azure Project

  1. On the menu bar, choose Debug, Start Debugging (Keyboard: F5).\

The storage emulator and the compute emulator for Visual Studio are started. These emulators enable you to run and debug your Windows Azure application locally before you publish it to Windows Azure.

2.      To manage your local deployments, open the shortcut menu for the Windows Azure icon in the notification area and then choose Show Compute Emulator UI.

The Windows Azure Compute Emulator is displayed.

3.      Choose WebRole1 to display the instances of the web role, as shown in the following illustration. Choose a specific instance to view only that individual instance.

 

Install and Create a Windows Azure Application in VS 2010

To view the data that you added to the blob, on the menu bar choose View, Server Explorer. Open the Windows Azure Storage node in the tree, and then choose the Development, Blobs node. Double-click the quicklap node, as displayed in the following illustration:

Install and Create a Windows Azure Application in VS 2010

The data in the blob is displayed in the quicklab tab.

If you are using the storage emulator, open the shortcut menu for the Windows Azure icon in the notification area and then choose Show Storage Emulator UI to bring up the following dialog, which will allow you to control the running storage services as well as reset all data.

Install and Create a Windows Azure Application in VS 2010

After reading this article you can easily create and build your first windows azure application.


Don't want to miss updates? Please click the below button!

Follow MindStick