Wednesday, February 25, 2009

WCF Queued Dual HTTP Request Response Router

There are a lot of examples available for how to make WCF-based publish/subscribe messaging solutions, but not very many thay provides a simple queued dual HTTP request-response router. IDesign provides the queued Response Service from Juval Löwy's book Programming WCF Services, which provides a feature rich set of WCF goodies. Recommended. I've used it in combination with Sasha Goldshtein's Generic Forwarding Router to create a dual channel queued router.

The router container uses HTTP endpoints externally to interact with consumers, and MSMQ queues internally to talk to the service providers. This gives fewer queues to manage and monitor, and the consumers need not know anything about MSMQ.

The message forwarding ChannelFactory is cached for best performance. Read more about Channel and ChannelFactory caching in Wenlong Dong's post Performance Improvement for WCF Client Proxy Creation in .NET 3.5 and Best Practices.

Some useful resources related to making this router work:

Note the poorly documented requirement that the WAS activated service endpoint path must be reflected in the MSMQ queue name:

<add key="targetQueueName" value=".\private$\ServiceModelSamples/service.svc" />

<endpoint address=

Failure to adhere to this convention will prevent messages added to the queue from automatically activating the WAS-hosted WCF service. Also ensure that the WAS app-pool identity has access rights on the queues.

Download the router example code here. The code is provided 'as-is' with no warranties and confers no rights. This example requires Windows Process Activation Service (Vista/WinServer2008), MSMQ 4.0 and .NET 3.0 WCF Non-HTTP Activation to be installed.


Peter said...

Hi, I enjoyed reading your article.
Very well done. I do have a few questions. Do you have any brief explanations of each project?
Thanks so much.

Kjell-Sverre Jerijærvi said...

First, know that .NET 4.0 will provide a WCF router ootb that supports more scenarios than just one-way queued contracts.

ServiceModelEx: code from with a few added classes and some fixes on MSMQ code to support WAS activated queues.

WcfQueuedDualRouter.Host (runnable): the actual router.
WcfQueuedDualRouter.Test: the router tests.

DemoServiceProvider: the demo service, as a component that needs a host application.
DemoHost (runnable): a console application to host the demo service component.

DemoServiceConsumer: the consumer of the demo service , as a component that needs a client application.
DemoClient (runnable): a console application to host the consumer component.

DemoSoapClient: just another demo consumer that use the same demo service over an extra set of SOAP endpoints.