-
Notifications
You must be signed in to change notification settings - Fork 24
Getting Started with Web Roles
A Web Role that is to use LightBlue is created using the standard Azure tooling. After creating a Web role add a NuGet reference to LightBlue using:
Install-Package LightBlue -pre
The Worker Role must be using the 2.4 version of the Azure SDK. The LightBlue NuGet package will ensure that the requisite NuGet packages for other dependencies are installed.
Except where the role uses the Azure APIs coding a web role is no different to how it would otherwise be implemented. Instead of calling the Azure APIs the LightBlue APIs are substituted. These may be accessed via LightBlueContext or via an IoC container (see Configuring IoC).
Web role hosting involves two processes. The LightBlue host runs the background process for the role. It also starts IIS Express to host the website. The host for webroles is LightBlue.WebHost.exe
, provided by the LightBlue.Hosts NuGet package.
The LightBlue.WebHost.exe
process may be executed in a script or from the command line. Unlike worker roles a web role project cannot be started from within Visual Studio by setting an external process to run. This will cause Visual Studio to start the website which will not configure it for LightBlue.
The host requires a number of command line parameters to be passed in order for it to correctly locate the role and the appropriate configuration. They are:
- -a The full path to the Web Role assembly.
- -n The name of the Web Role. This is the name it is listed under in the Cloud Service project. It is used to look up the settings for the role from the configuration file. Specifying an unknown role name will result in an error.
- -t (optional) The title of the Web Role. This is used as the window title for the host process. Useful for when there are multiple hosts running. If not specified the name of the role is used.
- -c The path to the configuration. If this path is a file that file is assumed to be an Azure .cscfg and is parsed for the relevant settings (expected to be under the element identified by the role name). If it is a directory LightBlue looks for the file ServiceConfiguration.Local.cscfg in that directory.
- -p The port that the site is to run on.
- -s Flag indicating whether the site should be run using SSL [true/false].
- -h The hostname the site is to run on. Defaults to localhost.
From version 0.1.11 you must specify both -p and -s or not specify either. If the values are not specified then the first endpoint specified for the role in ServiceConfiguration.csdef is used to supply them.
The host process is installed by the command:
Install-Package LightBlue.Hosts -pre
This package is a solution level package and does not get installed into any particular project. The hosts do not directly reference the LightBlue assembly and are not strictly required to be of the same version although different versions are not guaranteed to be compatible.
Web roles may also be fired up in the Azure emulator or deployed to actual Azure in the same way as any other role. This is detected automatically and the appropriate implementations of the LightBlue APIs are provided. No configuration changes are required between environments.
In order to make SSL work with IIS Express it is necessary to configure Windows to allow it to run. In order to do this run two commands:
netsh http add urlacl url=https://<hostname>:<port>/ user=Everyone
netsh http add sslcert ipport=0.0.0.0:<port> appid={214124cd-d05b-4309-91f9-9caa44b2b74a} certhash=<hash of your certificate>
The certificate (including private key) should be in your machine's certificate store and should have a path to a trusted root certificate. When copying the certificate hash for your certificate be careful not to copy any hidden characters as this will cause the netsh
command to fail.
(The appid parameter value does not appear to be significant. This value was borrowed from Scott Hanselman)
If you wish to use an IoC container with your worker role this can be added using the optional Autofac Integration.