« SQL Azure Overview - Part 3 (15 minutes) | Main | How to speed up Windows Azure Development (Part 2 of 2, 9 minutes) »

How to speed up Windows Azure Development (Part 1 of 2, 18 minutes)

This is part 1 of 2 screencasts I recorded that show how to speed up Windows Azure Development (see part 2 here).   Specifically, in this screencast I create a sample Windows Azure project with one web role - but the web role is smart enough to load its settings when running the Azure fabric or not - allowing it to be hosted in IIS.

For more articles, screencasts and tips check out www.ehuna.org – you can also follow me on twitter.com/ehuna


Here’s what is covered in the video:

1. To get this working you need Microsoft Visual Studio and the Windows Azure SDK (November 2009 CTP) – you can get it here at -
  http://www.microsoft.com/windowsazure/windowsazure/
2. Create a new CloudService project (VB.Net) called “AzureSpeed1”, with an ASP.NET web role called “AzureSpeed1_WebRole”. 
3. Create a setting in the ServiceConfiguration.cscfg file.
4. Running the project in the Windows Azure local development fabric.  Benefits of running in a virtual machine.  A bit slower since we’re running in a virtual machine. 
5. Displaying a setting in the default.aspx page – web role still running in the local development fabric.
6. How I’m impatient – I’m used to years of RAD – Rapid Application Development with IIS, ASP.NET, VB.NET and Visual Studio.
7. You can run your web roles in the local development fabric – but you can also run them in IIS!  Make sure handle settings and logging properly.
8. Add new IIS site, match azure local development fabric and IIS ports (change by one number – e.g. 8080 and 9080).  Try loading the page and see the exception.
9. Knowing whether you’re running the Azure fabric or not.
10. Smarter function to read settings – if not running in the cloud from the web.config.
11. We’re back to RAD development!  Build your web role (really just an ASP.NET site) and start testing your ASPX pages – no need to run the local development fabric.
12. Conclusion: whenever you implement a feature in your Windows Azure projects, make sure you add support for running both in the Windows Azure fabric (local development fabric or Staging/Production cloud) or on-premise hosted in IIS.  Settings, logging, and ASP.NET sessions are examples of features that need to support both.

Below you can find sample code and additional tips related to this screencast.

How to speed up Windows Azure Development (Part 1 of 2, 18 minutes)
By Emmanuel Huna, http://www.ehuna.org, twitter.com/ehuna

Download the Visual Studio Solution here:
  http://blog.ehuna.org/files/Visual-Studio-Solution-AzureSpeed1.zip (26 KB)

  image

IIS
Once you’ve opened the solution and compiled it in Visual Studio 2008, create an IIS web site (watch video if you don’t know how).

Settings
Settings should be in both ServiceConfiguration.cscfg and Web.Config

Settings > ServiceConfiguration.cscfg

<?xml version="1.0"?>
<ServiceConfiguration 
serviceName="AzureSpeed1"
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"> <Role name="AzureSpeed1_WebRole"> <Instances count="1" /> <ConfigurationSettings> <Setting name="DiagnosticsConnectionString" value="UseDevelopmentStorage=true" /> <Setting name="MySetting" value="This is my setting" /> </ConfigurationSettings> </Role> </ServiceConfiguration>

Settings > Web.Config

  <appSettings>
    <add key="MySetting" value="This is my setting from web.config" />
  </appSettings>

VB.NET Code Behind

Imports Microsoft.WindowsAzure.ServiceRuntime
Module modUtils
  Public bIsAzure As Boolean = False
  Public sMySetting As String = "" 

  Public Sub LoadSettings()
    bIsAzure = IIf(RoleEnvironment.IsAvailable, True, False)
    sMySetting = GetSetting("MySetting")
  End Sub
  
Function GetSetting(ByVal sSettingName As String) As String Dim sReturn As String = "" Try If bIsAzure Then sReturn = RoleEnvironment.GetConfigurationSettingValue(sSettingName) Else sReturn = ConfigurationSettings.AppSettings(sSettingName) End If Catch ex As Exception 'LogMessage("Error retrieving setting '" + sSettingName + "'; Exception: " + ex.ToString, EventLogEntryType.Information) sReturn = "" End Try Return sReturn End Function End Module

Good Times!

| More

Comments



About

This page contains a single entry from the blog posted on January 28, 2010 9:16 PM.

The previous post in this blog was SQL Azure Overview - Part 3 (15 minutes).

The next post in this blog is How to speed up Windows Azure Development (Part 2 of 2, 9 minutes).

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.35