IIS7 Hostable Web Core Custom Service (WebCoreService)

Hostable Web Core (known as HWC) is a new concept in IIS7 to host a website/webservice inside your own process. In short a smaller hosted version of IIS (an IIS7 express edition?).
This is accomplished by making a LoadLibrary call to load hwebcore.dll (%systemdrive%\Windows\System32\inetsrv\hwebcore.dll)

From IIS7 onwards you can administer IIS7 remotely using IIS Manager (through HTTPS). When you connect remotely you are actually connecting to a "Web Management Service" called WMSVC. This service uses HWC so that it's not dependent on IIS7 services directly.

I had some idea around building alternative UI for IIS7, but since WMSVC service calls are not publicly documented I didn't want to start using it since my application might break anytime. So HWC was a surprise to me but with a glitch. I'm too used to managed code that I haven't written C++ code from last 6years. During 1996-2000 C/C++ was my favorite language and then got into languages which are less fussy (VB/VB.net & C#).

But I had multiple challenges 1) Writing something in a language which I've not used for last 6 years. 2) Writing a windows service which I haven't done before.

Before diving into the code let's see limitations of HWC (Calling it limitation is wrong so let's say it's by design)

  1. Only one application pool
  2. Only one website/webservice
  3. Separate configuration file
  4. No monitoring like available for IIS7 application pools
  5. Require IIS7 to be installed

PS: Project files are in VS2008 but the application doesn't have any dependency with newer versions.

Ingredients of my WebCoreService.

  1. Native Windows Service which host HWC which provides install/uninstall options
  2. Good IIS7 configuration file (applicationHost.config) which contains all configuration required to run ASP/ASPX/ASMX... pages
  3. TODO: Web/WCF service hosted inside this service which publishes all the management API's for consumption
  4. TODO: Alternate client for managing IIS7
  1. Native Windows Service which host HWC. Below is a screenshot to see the options available using command-line
     help
  2. All the configuration including where the website points to and what port it's hosting the site etc are mentioned in the configuration file called "WebCoreService.config". This is nothing but the actual applicationHost.config file after few of those things removed from it.
  3. This could be a good managed Webservice or WCF service which would expose management API's.
  4. How about a Mobile Client? which supports SMS (Texting). Just imagine sending a text message to recycle one of the application pool ?
    Hosting management site running inside this?
    These are only few of those possibilities though :) think crazy stuff and let me know.

How to RUN the service?

Extract the zip files with source and the binary files.
Follow these steps to setup the service (make sure you are doing this from an elevated command prompt)

  • Create a folder called "TestPath" inside your "C:\inetpub\" folder
  • Create 2 folder inside called "wwwroot" and "Logs"
  • Drop "time.asp" and "time.aspx" pages inside the "wwwroot" folder
  • Enable event logs notification from the service
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\WebCoreService]
    Create a string key "EventMessageFile" and set value as full path to "sample.dll" under the bin folder
    Create a DWORD key "TypesSupported" and give value of "00000007"
  • Goto the folder where the EXE file resides "WebCoreService.EXE"
  • Install the service using the following command
    WebCoreService install
  • Start the service using the following command
    net start WebCoreService
  • Browse to the page http://localhost:8080/time.asp

Bingo! Hostable webcore service is ready.

All the configuration mentioned above like folder path, port number etc can be modified inside the configuration file "WebCoreService.exe.config"

Do let me know if you have any questions or suggestions or even ideas !!!
Source & binary => http://code.msdn.com/hwc/

2 Comments

Comments have been disabled for this content.