Windows Azure Tools for Microsoft Visual Studio extend Visual Studio to enable the creation, building, debugging, running and packaging of scalable services on Windows Azure.
Creating a new Cloud Service
Start Visual Studio 2008 or Visual Studio 2010 Beta 1 as an administrator.
Create a new project. (File | New | Project)
In the C# and VB project templates notice a new group called “Cloud Services” and select the “Cloud Service” template
Give the project a name and hit Ok
Add a Web Role to the solution by selecting the “ASP.NET Web Role” item and clicking the right arrow.
Note that you can easily add multiple Web and Worker roles to your Cloud Service solution.
Rename “WebRole1” to “MyWebRole” by clicking on the edit button on the right side of the item (will appear on mouse over) and click “OK”.
You should have a solution with two projects
- A Cloud Service project
- A Web Role which is an ASP.NET Web Application
Solution explorer will look like this:
Modify the web role project
Go to Default.aspx and switch to design view.
Add a heading.
Add a button with an event handler.
Double click the button to add an event handler when the Button is clicked.
In the Event Handler, write a trace message. In order to use the RoleManager API, you will need to add a using to the Microsoft.ServiceHosting.ServiceRuntime namespace.
using Microsoft.ServiceHosting.ServiceRuntime;
protected void Button1_Click(object sender, EventArgs e) { RoleManager.WriteToLog("Information", "Doing my lap around the tools and clicking the button"); }
Add a breakpoint to the line of code you just added in the Button Click Event Handler.
Building and Debugging the Cloud Service
Build the project or right click the Cloud Service project and select “Build”.
Interested in the build output? Right click the Cloud Service project and select “Open Folder in Windows Explorer”. Drill into the bin"debug directory to see the build output (this is produced by the Windows Azure SDK tool - cspack.exe).
Modify the number of instances to run.
Select a Role under the Roles node in the Solution Explorer, right click and select “Properties”.
In the Properties Window, set the instance count property to “2”.
Note that the current limitation for the number of instances of each Role on Windows Azure in the Cloud is 2 per Role.
The ServiceConfiguration.cscfg file should look like this:
<?xml version="1.0"?>
<ServiceConfiguration serviceName="CloudService9" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="MyWebRole">
<Instances count="2"/>
<ConfigurationSettings/>
</Role>
</ServiceConfiguration>
Debug the project
Select Debug -> Start Debugging (F5).
Note that a Development Fabric icon is added to the system tray that allows you to bring up the Development Fabric UI or to shutdown the Development Fabric altogether.
If you click “Show Development Fabric UI” the following window will be brought up that will give you additional control over your running Deployments and a view of their logging.
The trace message you log in the button push will show up in the log window for the instance that services the request.
If this is your first time using Development Storage, the Development Storage initialization dialog will come up:
Hit “OK” to dismiss.
Note that a Development Storage icon is added to the system tray that allows you to bring up the UI to control the Development Storage services.
Clicking on “Show Development Storage UI” brings up the following dialog:
IE will start up automatically pointing to your web site. The full address will be similar to http://127.0.0.1:8080/default.aspx .
When you click the button, you will hit the breakpoint that you set in the debugger.
Look at the Development Fabric UI to see your message in the trace log.
Note that any one of the instances could process the request.
Publishing the Cloud Service
Create the Service Package (cspkg) by right clicking on the Cloud Service project node and selecting “Publish”.
Explorer will open to the folder containing the Service Configuration file and Service Package (.cspkg). This file along with the Service Configuration file (cscfg) are the files you upload via the Azure Services Developer Portal to run your application on Windows Azure.
A browser window will open to the Azure Services Developer Portal where you can upload and deploy your service. (See Deploying a Service on Windows Azure for more information)
This completes the Quick Lap around the Windows Azure Tools for Microsoft Visual Studio.