After you have downloaded the source code from http://bostonazure.codeplex.com you can do the following to get it running in the Azure Development Fabric.
1. If you haven’t already installed the June 2010 Azure SDK – download it an install it: Windows Azure Tools for Microsoft Visual Studio 1.2 (June 2010)
2. Open the BostonAzureSite.sln with an elevated user version of Visual Studio 2010 (run as administrator)
3. Run the solution to verify it will build and launch the browser with a url something like: http://localhost:9999

Once you have verified the solution works, now perform the following to get it running in the Azure Development Fabric

Add the Web Role to the Solution and Configure

1. In the Solution Explorer, right click on the solution name and choose Add -> New Project..
This will launch the New Project dialog
image1.png
2. In the top middle of the dialog, make sure the .NET Framework 4 is selected
3. Then in the templates tree to the left, choose Cloud and then the Windows Azure Clouse Service from the template listing.
4. Name the project BostonAzureSite.WebRole and
5. Click OK
6. When the New Cloud Service Project dialog shows, click OK (we will add the existing MVC site to the role manually).

In you Solution Explorer, you will now find the new BostonAzureSite.WebRole project.
1. In the Solution Explorer, right click on the Roles folder in the new BostonAzureSite.WebRole project
image2.png
This will launch the Associate with Role Project dialog
2. Select the BostonAzureSite from the list and click OK
The BostonAzureSite should now show up under the Roles folder:
image3.png

Azurize the MVC Project

The Web Role project is now ready. Now we need to 3 things to the MVC project.
1. References to the Azure libraries
2. A WebRole.cs class
3. Configuration setting to tie the diagnostics into Azure

Add the References

1. In your Solution Explorer, find the BostonAzureSite project, right click on the References folder
This will launch the Add Reference dialgog
2. On the .NET tab, find the Azure libraries and reference them. The fastest way to find them that I’ve found is to sort the listing by version so the 1.0.0.0 items are listed first and look for the following 3 highlighted libraries.
  • Microsoft.WindowsAzure.Diagnostics
  • Microsoft.WindowsAzure.ServiceRuntime
  • Micrsofot.WindowsAzure.StorageClient
image5.png
3. Select all 3 shown above (by holding down the Ctrl button) and click OK.
That’s all the references we should need right now.

Add a WebRole.cs file

Normally when you create a Cloud Service project from scratch the template for the project you choose will have this file already, but since we are converting an existing project to run in Azure you need to add it manually.
1. In the Solution Explorer, right click on the BostonAzureSite project and select Add -> Class…
2. Create a new class named WebRole.cs
3. Copy and paste the following into the contents of the class:
using System.Linq;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace BostonAzureSite
{
    public class WebRole : RoleEntryPoint
    {
        public override bool OnStart()
        {
            DiagnosticMonitor.Start("DiagnosticsConnectionString");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            return base.OnStart();
        }

        private void RoleEnvironmentChanging(object sender, 
            RoleEnvironmentChangingEventArgs e)
        {
            // If a configuration setting is changing
            if (e.Changes.Any(change => change is 
                RoleEnvironmentConfigurationSettingChange))
            {
                // Set e.Cancel to true to restart this role instance
                e.Cancel = true;
            }
        }
    }
} 

That’s it for the WebRole class. The default for the Web Role currently is to use the local storage for diagnostics – so if you don’t have it setup you may want to comment line 11 which starts the diagnostics listener and connects it to the storage setup in the “DiagnosticsConnectionString” setting in the Web Role project.

Add the Configuration Setting for Diagnostics

The WebRole.cs starts the diagnostics process, but until you wire the trace listener up nothing will go out when you use the System.Diagnostics.Trace.Write() statements.
1. Open the web.config file
2. Find the opening <configuration> element
3. Copy and paste the following that opening configuration element:
<system.diagnostics>
    <trace>
        <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, 
Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
                <filter type=""/>
            </add>
        </listeners>
    </trace>
</system.diagnostics>


4. Save the project and build to verify there are no build errors
5. Run it and the Developer Fabric should startup and the project should now launch with a url like: http://127.0.0.1:81

Verify the Development Fabric is running

1. In your tray, right click on the Blue Azure flag and choose Show Development Fabric UI
image4.png
The Development Fabric UI should now show.
2. Expand the nodes on the tree control for the deployments to find the BostonAzureSite node
3. Click on the Green dot and you should see the diagnostics output of the application starting up.
image6.png
That’s it – it is now running in the dev fabric.

Last edited Jun 25, 2010 at 1:43 PM by JasonHaley, version 7

Comments

No comments yet.