Dissection of a Windows Azure SDK 1.3 based ASP.NET Web Role in Full IIS mode & HWC

Let's start from
the point that you have an ASP.NET based WebRole as MainWebRole.DLL which you
have created using Windows Azure SDK 1.3. The ServiceConfiguration.CSDEF
setting can run your webrole in following two modes:

1. Full IIS
Mode

2. HWC (Hostable
Web Core) Mode

Full IIS Mode:

Let's Start
from Full IIS Mode. In this mode you will have your ServiceConfiguration.CSDEF
will have a section name <Sites> as below:

<?xml version="1.0" encoding="utf-8"?>

<ServiceDefinition name="AzureVMAssistant" xmlns="https://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">

  <WebRole name="MainWebRole">

    <Sites>

      <Site name="Web">

        <Bindings>

          <Binding name="Endpoint1" endpointName="Endpoint1" />

        </Bindings>

      </Site>

    </Sites>

    <Endpoints>

      <InputEndpoint name="Endpoint1" protocol="http" port="80" />

    </Endpoints>

    <Imports>

      <Import moduleName="Diagnostics" />

      <Import moduleName="RemoteAccess" />

      <Import moduleName="RemoteForwarder" />

    </Imports>

  </WebRole>

</ServiceDefinition>

Above
highlighted <Sites> part is important as it makes your application to run
in Full IIS mode. When you RDP to your Windows Azure VM you will see two
processes are handing your service:

1. WaIISHost.exe

2. w3wp.exe

 

If you look
for the .net assemblies in both the above process you will see the MainWebRole.DLL
is loaded with both the process.

 

WaIISHost.EXE

w3wp.exe

HWC (Hostable Web Core) Mode

In this mode
you will have your ServiceConfiguration.CSDEF will MUST have cmmented the
<Sites> section as below:

<?xml version="1.0" encoding="utf-8"?>

<ServiceDefinition name="AzureVMAssistant" xmlns="https://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">

  <WebRole name="MainWebRole">

    <!--<Sites>

      <Site name="Web">

        <Bindings>

          <Binding name="Endpoint1" endpointName="Endpoint1" />

        </Bindings>

      </Site>

    </Sites>-->

    <Endpoints>

      <InputEndpoint name="Endpoint1" protocol="http" port="80" />

    </Endpoints>

    <Imports>

      <Import moduleName="Diagnostics" />

      <Import moduleName="RemoteAccess" />

      <Import moduleName="RemoteForwarder" />

    </Imports>

  </WebRole>

</ServiceDefinition>

Just making
the above change caused your application to run very differently. You will see
only one process WaWebHost.EXE is taking care of your application and our MainWebRole.DLL
is loaded in this process as below:

Summary:

The gist to
understand here that there is a significant difference in how your code is
hosted in Windows Azure depending on whether you choose HWC or Full IIS.

As you know
that your Web Role have two important pieces:

1. RoleEntryPoint
(OnStart method of your WebRole class which derives from RoleEntryPoint)

namespace MainWebRole

{

    public class WebRole : RoleEntryPoint

    {

        public override bool OnStart()

        {

            // For information on handling configuration changes

            // see the MSDN topic at https://go.microsoft.com/fwlink/?LinkId=166357.

            return base.OnStart();

        }

    }

}

2. Your
WebSite Content

 

When you have select to use HWC Mode:

       The RoleEntryPoint methods and your web site itself run under the WaWebHost.exe
process.

       In the following
diagram you can see how MainWebRole.dll is hosted in WaWebHost.EXE

 

When you have select to use full IIS
Mode:

1. RoleEntryPoint runs under WaIISHost.exe,

2. Your web site runs under a normal IIS w3wp.exe process.

       In the following
diagram you can see how MainWebRole.dll is hosted in WaIISHost.EXE & w3wp.exe

 

When you
decide to upgrade your ASP.NET web role from Windows Azure SDK 1.2 to Windows
Azure SDK 1.3, please consider following scenarios as below:

 

1. Configuration Settings in Full IIS
Mode:

You will see
on common problem with full IIS that code running in RoleEntryPoint cannot read
web.config and cause error.

The reason
for this problem is that your web site uses web.config as configuration file
however RoleEntryPoint does not have access to web.config because RoleEntryPoint
code is running in separate process (WaIISHost.exe) then the website (w3wp.exe).

The
WaIISHost.exe process looks configuration settings in a file name WaIISHost.exe.config
so you will need to create a file name WaIISHost.exe.config with all the
necessary settings and place along with your application to avoid such problem.

 

2. Problem accessing Static Members
from your Web site and RoleEntryPoint

As
RoleEntryPoint and Website is running on two separate processes the static members
will not be shared in between these two.