And now: a no thrills .NET WCF technology post in the hope of saving some developer’s time while trying to figure out wtf is going wrong.
The problem looks like this:
Your w3wp process crashes, or your IIS application pool gets stopped for no clear reason. Restarting it only causes it to stop again after a few seconds.
Deactivating the Net.Msmq Listener Adapter in the service control panel makes the problem stop.
Your Windows event log shows errors like this:
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/1/ROOT
Message: The service ‘~/foobarQueue’ does not exist.
StackTrace: at System.ServiceModel.ServiceHostingEnvironment.NormalizeVirtualPath(String virtualPath)
at System.ServiceModel.Channels.MsmqHostedTransportManager.HostedBindingFilter.MatchFound(String host, String name, Boolean isPrivate)
at System.ServiceModel.Channels.MsmqBindingMonitor.MatchQueue(MatchState state)
at System.ServiceModel.Channels.MsmqBindingMonitor.ProcessFoundQueues(MessageQueue queues, Dictionary`2 knownQueues, Boolean isPrivate)
at System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer(Object state)
at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state)
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
The problem is in the Net .Msmq Listener for the Windows Process Activation Service (or WAS for short). WAS checks all your MSMQ queues on the system and tries to figure out if there are any WCF services that it should poke to start reading the messages in the queues. Problem is in the case mentioned above there are also queues on the system which do not have WCF services that process them. WAS tries to activate a service for this “foobarQueue” anyway, which results in an exception.
And here is how you fix it:
- Make sure all WCF services that should be processing queues are in a virtual directory on IIS. For example http://localhost/foo/foobarservice.svc
- The queues to process will also have to resemble this virtual directory in the queue-name, like: .\private$\foo/foobarservice.svc
- Set your web site’s MSMQ bindings to localhost/foo instead of just the default localhost.
You do this in the IIS Management tool by right clicking your web site, then click Edit Bindings in the pop-up, select the MSMQ binding and edit the bindings’ information as mentioned above.
That should do the trick.