With the release of Windows Vista (and subsequently Windows Server 2008), a new way to host WCF services was introduced: Windows Process Application Service (WAS). Services that use MSMQ now have the option of being hosted in WAS. One of the most frequently asked questions relates to matching the service file (*.svc file) with the queue that needs to be monitored. This article explains most of the behavior, but this blog post aims to clarify some of the subtleties.

 

The queue is matched using two criteria: the virtual directory and the service file name. The virtual directory is the directory structure below the ‘wwwroot’ folder in the IIS directory. For example, if the path for a service file is ‘C:\inetpub\wwwroot\MyServices\ExampleService\ExampleService.svc’, the virtual directory is ‘MyServices/ExampleService/’. The service file name is the full name of the file, including the .svc extension. In this trivial example, the matching queue could be named ‘MyServices/ExampleService/ExampleService.svc’.

 

A complication arises when WAS discovers a service file in a virtual directory, whereby it considers all queues in that same virtual directory to be related to a service. If, in the previous example, there was a second queue named ‘MyServices/ExampleService/AnotherService’, this would cause an error. This queue can’t possibly match a service file (due to the lack of .svc extension), but is in an application virtual directory that has a service. This seems an unlikely scenario – any other virtual directory (or none at all) in the name of the queue would avoid this altogether.

 

This behavior may become problematic when you consider the root application – when the service file is placed directly into the wwwroot folder. The queue name now only has to match the service file name, as no virtual directory is appended. For example, a service file in ‘C:\inetpub\wwwroot\NewExampleService.svc’ would match a queue named ‘NewExampleService.svc’. WAS now considers the root virtual directory to contain a service. Any queue present on the machine that does not contain a forward slash (‘/’) and doesn’t match a service file will cause an error in WAS!

 

Queues that are not used by WAS rarely contain forward slash characters. It is important to consider this scenario when designing your system. Avoid placing services directly into the root directory, if possible. Only do so if the system will only ever have queues that are associated with WAS hosted services.

 

--Nathan Healey