Author: Jim Nakashima
Prerequisites
This walkthrough assumes you have done the Quick Lap Around the Windows Azure Tools
for Microsoft Visual Studio and have a Cloud Service project working locally
on the Developer Fabric and Developer Storage running from Visual Studio.
It also assumes that you have access (a token to redeem) to
create both Storage Accounts and Hosted Services. See the Azure Services Platform
site for more information.
Workflow
A good process to follow when moving a locally development
Cloud Service to run on Windows Azure is to:
- Get your service running locally
- Run your service locally in the Development
Fabric using a Windows Azure Storage Account
- Run your service on Windows Azure using a Windows
Azure Storage Account.
.jpg)
Moving from Developer Storage to a Windows Azure Storage Account
While running your application on your local machine in the
Development Fabric, change your Cloud Service to work against a Windows Azure
Storage account. This involves two
steps:
- Get a storage account
- Make the configuration changes to run your Cloud
Service against your storage account.
This is a great way to ensure that your Cloud Service will
run when hosted on Windows Azure.
Creating a Storage Account
Navigate to the Azure Services Developer
Portal and sign in with your Live ID.
From the Portal page, you can select “New Project” and click
on “Storage Account”.
.jpg)
Fill in a friendly name for the storage account (this is not
the Service/Domain Name – you will be prompted for that on the next page). Optionally enter a project description.
.jpg)
Then fill in the service/domain name on the next page.
.jpg)
You’ll get a summary for your storage account:
Configuration Changes to use Windows Azure Storage
When using the StorageAccountInfo type from the
StorageClient sample in the Windows Azure SDK, you will have settings in one of
your configuration files (Service Configuration cscfg or web.config) that you
will want to update to run against Windows Azure.
From the summary page for you Cloud Storage, you can find
the end point and access key that you use to modify those configuration files.
Update the
AccountName to the Service/Domain Name you entered. This is the first part of your domain,
tablesamplestorage (all lower case) in the example above.
Update the AccountSharedKey to be the Primary Access Key
that you got back on your summary page.
Note: The Secondary Access Key provides the same access to
your storage account as the Primary Access Key and is generated as a backup
should your Primary Access Key get compromised.
You can also regenerate the keys if necessary.
Note: The Endpoints listed on the summary screen are not the
URLs that you will use to access the storage services if you are using the
StorageAccountInfo type in the StorageClient library in the Windows Azure SDK
samples. Please see the table below.
Here’s an example of the update Service Configuration file:
<Setting name="AccountName"
value="tablesamplestorage"/>
<Setting
name="AccountSharedKey" value="9OrFugcDnR1vbzzcIgrjJE3MsWzr/z2xZrf/6yhEQHF7c53KFJzfvRmbHv2vUF9hAliOmJWAoDFNu7nkv+RuJw=="/>
<Setting
name="TableStorageEndpoint" value="http://
table.core.windows.net"/>
Debug your Cloud Service Locally Running against Windows Azure Storage
Hit F5 to debug your Cloud Service and ensure that
everything works correctly against Windows Azure Storage.
Once you have everything working in that configuration, you
are ready to deploy to the Windows Azure!
Create a Hosted Service
Navigate to the Azure Services Developer
Portal and sign in with your Live ID.
Click on “New Project” in the upper left hand corner, click
on “Hosted Services”:
.jpg)
This will take you to a page where you can specify the
project name and description. Note that
on this screen, the project name is a friendly name used by the Developer
Portal.
.jpg)
After clicking next, you will be prompted to select a domain
name for your Hosted Service project.
.jpg)
After the project is created, you will be taken to a summary
page for your project. On this page, you
will see the Application ID, Domain, Return URL, Secret Key, buttons to deploy
your project and the status of your deployment.
.jpg)
Setting the API Key in Visual Studio
Copy the Application ID and enter it in the Cloud Service
Project Properties of your Cloud Service project:
.jpg)
.jpg)
When you use the Publish command (Build -> Publish or
Right click on the Cloud Service Project and select Publish) in Visual Studio,
having the Application ID set will result in VS bringing up the Developer
Portal page specific to your Cloud Service Project. Otherwise, it will bring up the summary
page.
Hit “Save” to save the project file.
Deploying the Package from Visual Studio
Right click on the Cloud Service Project in Solution
Explorer and select “Publish…”.
.jpg)
This will build your package, open Windows Explorer up to
the location where the package was built and use Internet Explorer to browse to
the Developer Portal.
From this Portal page, select “Deploy”.
.jpg)
This will take you to a page where you can specify the
package and the configuration file to upload.
You can copy the path from the Windows Explorer window that
VS opened into this File Open dialog – which will make it easy for you to
select the Service Package (cspkg) and Service Configuration.
Note: The current
constraint for the number of instances you can run on Windows Azure as part of
the CTP is a maximum of 2 Web Role instances and 2 Worker Role instances.
.jpg)
The portal will then upload the package and deploy your
Cloud Service to staging.
This puts your roles in the “Allocated” state:
.jpg)
From Staging, you can test your Cloud Service on a staging
URL (the cloudapp.net URL that begins with a Guid) by clicking “Run”. His will put your Web Role in the
Initializing state.
.jpg)
When the Web Role is ready, the state will be changed to:
.jpg)
Once your roles have been started, you can test by
navigating to the staging URL.
After you are happy with your Cloud Service on staging, you
can promote it to production by clicking on the promote button.
.jpg)
Your service will now be running at its final URL.
.jpg)
Also note that you can click “Configure…” to copy your event
logs to a storage account or update the Service Configuration (cscfg). The Service Configuration can be update by
using the editor provided or by uploading a new Service Configuration file.