Part 1: Hello Azure – Learn Azure with me.
Posted by Vadim on January 19, 2010
I want to learn Windows Azure. I already have done some reading on the subject and created some simple Windows Azure applications. However, I believe that writing articles about Cloud Services will help me to get stronger understanding of the platform.
I will not tell you what Windows Azure is. I hope that you’re reading this because you know what it is and ready to learn it. I also hope that you already downloaded and installed Windows Azure Platform on your computer. If you haven’t done it, you can download it from Microsoft Windows Azure site.
My goal for this article:
- Create LearnAzure Cloud Service that displays “Hello Azure!” message.
- Set up your service online.
- Deploy the application to Azure Fabric.
Create LearnAzure Cloud Service.
Start Visual Studio. I’m going to use VS 2010 Beta 2 but it should work just fine with VS 2008.
Press Ctrl+Shift+N to create a new project. You also can select File –> New –> Project… from Visual Studio menu. You should see New Project dialog.
From Installed Templates select Cloud Service (if you don’t see Cloud Service template, than you need to install Windows Azure SDK). For the project name I typed “LearnAzure”.
Click on the OK button and you will see a New Cloud Service Project dialog box. In this dialog box, from the Roles, select ASP.NET Web Role because we want to create an ASP.NET Windows Azure application. Click on the right arrow to make ASP.NET Web Role appear in Cloud Service Solution list. By default Visual Studio will give “WebRole1” to your ASP.NET Web Role. This name is too generic; let’s rename it to “LearnAzureWeb”. To rename, move your mouse over WebRole1 and click on the little pencil icon on the right of the role. Now you can rename it to LearnAzureWeb.
After Visual Studio is done, you should have LearnAzure solution that has two projects: LearnAzure and LearnAzureWeb. LearnAzureWeb looks almost like any other ASP.NET application but there few differences.
If you expend References in our ASP.NET Web projects, you’ll see three additional references to Windows Azure assemblies:
Use Diagnostics namespace for your logging needs.
Use ServiceRuntime namespace when you need to interact with Windows Azure fabric.
Use StorageClient namespace when you need to work with storage services.
These assemblies are located in Program Files\Windows Azure SDK\v1.0\ref folder.
I know that right now this is not enough information for you to understand exactly what these names are for, and how to use them. But remember, this is just a “Hello Azure!” article. We’ll have plenty of time to discuss more advance subjects in the future posts.
You also can see WebRole.cs file in your LearnAzureWeb project. WebRole class provides callbacks to initialize, run, and stop instances of our ASP.NET role.
We have a working Azure application without writing a single line of code. However, if we start the application by pressing Ctrl+F5 or F5 in case you wanto to start it with debugger, you will see an empty web page.
In your system tray you can find a new blue window flag icon. It tells you that Windows Azure simulation environment is running. It also means that the Development Fabric and the Development Storage services were started. You can right click on this icon to see User Interfaces either for the Development Fabric or Development Storage services. You also can
shutdown any of these services using this icon.
We are done but I hate to look at an empty web page; therefore, I’m going to add “Hello Azure!” to the body of Default.aspx page.
<body> <form id="form1" runat="server"> <div> Hello Azure! </div> </form> </body>
Here’s the output of our brand new Windows Azure application:
Setup your service online.
Now we know how to run our Hello Azure Cloud Service on Simulation Environment. Next we need to setup the service online. I assume that you already went to Microsoft Windows Azure site and have an Azure account setup.
In order to deploy our Hello Azure app. you need to log into your Azure portal with the Live ID you registered with. Below you can see my Windows Azure page. I have only one project: PDC08 CTP.
Next click on the project name. In my case I’m going to click on “PDC08 CTP” as it’s my project name. You should see the project page. On this page you can create a new hosted services and storage account. On my page you can see that a storage account “diagnosticsdata” that I created earlier.
I don’t have any hosted services yet. You and I are going to create “Learn Azure” hosted service. To create a new service, just click on New Service link; you have two these links on this page. One just above the left navigation bar and another on the right of the project name. You should see Create an new service page, similar to the image below.
On this page, we can create either a Storage Account or Hosted Service. We already decided that we want to create “Learn Azure” hosted service. Let’s click on Hosted Services link. You should see Create a Service page. Provide a service label and description for the service and then click the Next button.
You should go to the second part of Create a Service. On this page you need to enter a Public Service Name and choose an Affinity Group. The Public Service Name must be unique. I wanted to enter “LearnAzure” but it’s not available; therefore, I chose “LearnAzureWithMe”. The Public Service Name you’ll choose will be the first part of the URL for your service. Because it’s part of a URL, it must be unique and cannot have white spaces. Unfortunately, you have to come up with a different name because “LearnAzureWithMe” belongs to me now. You can click on the “Check Availability” button to see if the name you selected is still available.
The second part of the form is related to Hosted Service Affinity Group. Microsoft has many different datacenters around the world. You want to select a region that the best represents your audience / customers to get better performance. Also if you have services that are related you might want to deploy them to different datacenters for disaster recovery or geo-distribution purposes.
Deploy the application to Azure Fabric.
Finally we have a cloud space where to deploy our “Hello Azure!” application. But before we do so, we need to create the Service Package (.cspkg). We could use CSPack.exe utility that you can find in Azure SDK folder but it’s much easier to create the Service Package from Visual Studio by right clicking on LearnAzure Cloud Service project and select “Publish”.
Visual Studio executes CSPack.exe to create the Service Package. After all is done, you should see the folder containing the Service Package (LearnAzure.cspkg) and Service Configuration file (ServiceConfiguration.cscfg). .cspkg is a glorified zip file, you should be able to open it with any zip utility if you want to see what inside the package.
The next step is to deploy the Service Package and Service Configuration file. You can deploy directly to production, but I would recommend that you deploy to staging environment first. In order to deploy the application you need to go back to your Azure Portal. If you don’t see a staging ice cube next to the production one, click on the little arrow that is right of production cube.
Click on Deploy button under the staging ice cube. On the next screen, browse for your Service Package and Service Configuration file. You also will need to give a label for this deployment, my label is “v. 0.1”.
Click on Deploy button in order to deploy “Hello Azure!” application to Staging environment. The deployment process can take couple of minutes. After all is done the gray cube should magically transform to nice ice blue cube. Your Azure application is deploy but to test it, you need to click on Run button under Staging cube. You will see that the status flipped to “Initializing”. It might take few minutes for the status to change to “Ready”. You can test your application by navigating to your staging Web Site URL.
Next logical step after you tested our application on staging is to promote it to production. It’s very easy done by clicking on a circle with two arrows inside. If you need more clues to find the circle, it’s between Production and Staging cubes. You don’t actually move the application to different place. After you click on the circle, Windows Azure just flips production and staging environments. The old staging environment becomes our new production one and vice versa.
Now I can point my browser to http://learnazurewithme.cloudapp.net/ to use my perfectly useless application.
In this article, we learned how to create a simple Azure application. We also talked about new files and references that need to be added in order to run our app. in the cloud. Now you can tell all of your friends how to setup and deploy the Windows Azure application.
Next, we’re going to learn how to use Azure Service Configuration.