Author: Jim Nakashima
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 “Web Cloud Service” template
Give the project a name and hit Ok
You should have a solution with two projects
- A Web Role which
is an ASP.NET Web Application
Solution explorer will look like this:
.jpg)
Modify the web role project
Go to Default.aspx and switch to design view.
.jpg)
Add a heading.
Add a button with an event handler.
.jpg)
Double click the button to add an event handler when the
Button is clicked.
In the Event Handler, write a trace message.
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).
.jpg)
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”.
.jpg)
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="WebRole">
<Instances count="2"/>
<ConfigurationSettings>
</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.
.jpg)
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.
.jpg)
If this is your first time using Development Storage, the
Development Storage initialization dialog will come up:
.jpg)
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.
.jpg)
Clicking on “Show Development Storage UI” brings up the
following dialog:
.jpg)
IE will start up automatically pointing to your web site.
The full address will be similar to http://127.0.0.1:80/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.
.jpg)
Publishing the Cloud Service
Create the Service Package (cspkg) by right clicking on the
Cloud Service project node and selecting “Publish”.
.jpg)
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)
.jpg)
This completes the Quick Lap around the Windows Azure Tools
for Microsoft Visual Studio.