AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=2038&pId=-1
Build Your First Cloud Application Using Visual Studio 2010
page
by Vince Varallo
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30887/ 43

Introduction

One of the big buzzwords these days is "Cloud".  I see it on TV commercials during football games all the time and often wonder if 99% of the audience has any clue what the commercial is actually talking about.  The cloud is essentially a hosting service where you can host your databases or web sites.  It is a cost-efficient way of getting applications up and running without investing a lot of money in infrastructure.  This article will show you how to create an ASP.NET web site and deploy it to the Cloud.

Step 1: Download the SDK and tools for Visual Studio 2010

1.   Before you start creating applications for the Cloud you must first download the Windows Azure Tools for Visual Studio.  This can be found here.

2.   You also need to install and configure IIS 7.  You need to be running Windows 7, Vista, or Windows Server 2008.  Click here to read the instructions on setting up IIS 7.

3.   Now that you've installed IIS 7 you can install the Azure Tools by running the VSCloudService.exe file that you downloaded in Step 1.

4.   Once the Azure Tools are installed you need to install the hot fixes.  Depending on your operating system you'll need to install different ones.  They can be found here.

Step 2: Create a New Solution

1.   Launch Visual Studio 2010.

2.   Select FileàNew Project… from Visual Studio's menu.

3.   Expand the Visual C# templates and click on the Cloud node.  You should see the Windows Azure Cloud Service template.

4.   Change the name of the project to "MyCloudService" and click the OK button.

5.   The New Cloud Service dialog box should appear.

6.   Click on the ASP.NET Web Role in the left pane and click the > arrow to move it to the right pane.  This allows you to create a traditional ASP.NET web site for the cloud.  You can create a MVC web site, WCF service, background process or GCI application but for this example we'll stick with the traditional ASP.NET web site.

7.   Click the OK button.

8.   Visual Studio will add a whole bunch of standard files for a typical ASP.NET application. Some of these files include a master page, the login and password management pages, a style script, an about page, and a scripts folder. 

9.   Click the run button to start the project.  You should get the following message.

10. To remedy this you need to close Visual Studio and then launch Visual Studio again as an administrator.  You can do this by clicking on StartàAll ProgramsàMicrosoft Visual Studio 2010 and then right click on Microsoft Visual Studio 2010.  Select "Run as administrator" from the pop-up menu.  Now you need to open the MyCloudService project again.

11. Now try running the project again.  If you don't have SQL Express installed you'll get the following message.

12. The Output window will give you a more descriptive message.

"Windows Azure Tools: Failed to initialize Development Storage service. 
Unable to start Development Storage. Failed to start Development Storage: 
the SQL Server instance ‘localhost\SQLExpress’ could not be found.   
Please configure the SQL Server instance for Development Storage using the
‘DSInit’ utility in the Windows Azure SDK."

13. To fix this open the Windows Azure SDK Command Prompt.  This is found at StartàWindows Azure SDK v1.2àWindow Azure SDK Command Prompt.

14. Enter the following in the command window.

dsinit /sqlinstance:.

15. You should see the following dialog.

 

16. Click the OK button and then run the project again.  You should see the following web page.

Step 3: Deploy the Solution to the Cloud

Now that you have an application you can customize it to meet your needs.  For this article we'll just leave the application as is and deploy it to the cloud.  You'll first need to create an account for Windows Azure.  You can click here to view the list of offers from Microsoft.  You can create a free trial account by choosing the introductory offer.

1.   Before you deploy your project to the Cloud you need to create a Service Package.  This is done by right clicking on the MyCloudService node in your solution explorer.

2.   Select Publish from the pop-up menu.  You should see the Publish Cloud Service dialog box.

3.   Choose the option to "Create Service Package Only" and click the OK button.

4.   Visual Studio will create two files and open up Windows Explorer so you can upload them to the Windows Azure web site.  The two files are called MyCloudService.cspkg and ServiceConfiguration.csfg.

5.   Open up Internet Explorer and navigate to https://windows.azure.com/

6.   Once you log in to your account you should see your home page.

7.   Click on the "New Hosted Service" button in the upper left hand corner of the page.

8.   This will display the "Create a new Hosted Service" dialog.

9.   Enter "MyCloudService" for the name.

10. Enter "MyCloudService1" for the URL Prefix.  The URL Prefix must be unique across all sites so you'll have to append a number to the end of the prefix until the site tells you it is unique.  The name you enter here is the publicly available name that people will use to get to your web site.

11. Next, select a region where you want your site hosted.  I'll choose anywhere US for this example but you may want to choose a region closer to your target audience.

12. Under "Deployment options" choose "Deploy to production environment".  You can deploy to the stage environment and then promote stage to production but for this example we'll just deploy directly to production.

13. Enter "MyCloudService" for the Deployment Name.

14. Now you need to upload the package and configuration files that were created by Visual Studio in step 4.  Click the "Browse Locally…" button on the respective sections to upload the files.

15. Now click the OK button.  You'll get a warning regarding the fact that there is only one role with one instance for this deployment.  You can ignore the warning by clicking the Yes button.

16. The hosted service will then be created after a several minutes.  The first time I did this it took about 10 minutes.

17. Once the service is created you can then open Internet Explorer and navigate to http://mycloudservice1.cloudapp.net/ to see your application.  Remember to change the "1" in the URL to whatever number you used when you created the URL Prefix in step 10.

 

Summary

This article demonstrated how to create a very simple ASP.NET Cloud application and deploy it to the Cloud.  As you can see it isn't very difficult and it might send shivers down the spine of your network guy because it essentially puts him out of job.  The next article will show you how to create a database in the Cloud and create a Cloud application to interact with the database.  Good luck on your project and happy coding. 


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 6:46:09 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search