Introduction to Routing Service in WCF 4.0

Routing Service feature in WCF 4.0 is introduced by Microsoft to help developers in building WCF services with ease. The feature can route the message requests to other configured client WCF services based on the message content in the incoming client request. The routing principle is said to be Content Based Routing.

Need for a Routing Service

There has long been a need for this feature to be included in WCF 4.0. Below are some scenarios where WCF Routing Service would be useful.

1.Consider that multiple WCF services are hosted separately with their own end points, and based on the incoming SOAP message request from a client, routing should be done to the appropriate WCF service.

2.Say the client only communicates through HTTP binding and the WCF service processes only NET TCP bindings. In this case the router takes care of bridging the client and service operating on different protocols.

3.To act as a load balancer for the same WCF service deployed on different hosts.

4.To implement the fail over mechanism for a WCF service.

In-built Contracts

In order to implement the WCF Routing Service .NET framework 4.0 offers a few in-build contracts. These are placed under the namespace System.ServiceModel.Routing. The Routing Service can be configured with any of the contracts listed below. Based on these contracts the WCF communication channels are established.

1.ISimplexDatagramRouter: It is a one way model for which session is not mandatory. Ideal for performing tasks like logging, message queuing, etc.

2.ISimplexSessionRouter: It is one way but works on a session.

3.IRequestReplyRouter: It is the usual client message request and service response model.

4.IDuplexSessionRouter: It works over session and supports performing callbacks to the client

Message Filters

Message Filters are used by the WCF routing service to consider which part of the message has to be matched in order to perform the routing to the respective service. Below are some of the available message filters.





5.Even a Custom one can be created

Sample Code

In this section I will provide sample code for implementing WCF Routing Service. The routing service can be completely configured through the configuration file or through code behind. In my sample code I have chosen to use the configuration method.

1.Create a WCF service project, delete all the .cs files and add the reference to the library System.ServiceModel.Routing.

2.In the .svc file add the below entry.

<%@ ServiceHost Language="C#" Debug="true" Service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>

3.In the Web.Config add the below entries to configure the routing service.

              <service name="DemoRoutingService" behaviorConfiguration="MyRoutingServiceBehavior">
                                  <add baseAddress="http://localhost:5555/RoutingService/DemoRouter"/>
                     <endpoint name="RequestReplyBindingEP" address="http://localhost:5555/RoutingService/DemoRouter" binding="wsHttpBinding" contract="System.ServiceModel.Routing.IRequestReplyRouter"></endpoint>
                     <behavior name="MyRoutingServiceBehavior">
                           <serviceMetadata httpsGetEnabled="True"/>
                           <routing filterTableName="routingFilterTable"/>
              <endpoint name="GreetingService" address="http://localhost:6666/GreetingService/Greeting" binding="wsHttpBinding" contract="IGreetingService"></endpoint>
              <endpoint name="CalculatorService" address="net.tcp://localhost:6666/CalculatorService/Calculator" binding="netTcpBinding" contract="ICalculatorService"></endpoint>
                     <filter name="EPFilter" filterType="EndpointName" filterData="RequestReplyBindingEP"/>
                     <filter name="EPAddressFilter" filterType="EndpointAddress" filterData="http://localhost:5555/RoutingService/DemoRouter"/>
                     <filterTable name="routingFilterTable">
                           <add filterName="EPFilter" endpointName="GreetingService"/>
                           <add filterName="EPAddressFilter" endpointName="CalculatorService"/>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

Below is the sequence for the routing service configuration

1.Add routing service endpoints.

2.Add the routing service behavior along with a filter table name.

3.Add client service endpoints

4.Add the MessageFilters with filterType and filterData

5.Link the message filter with respective client endpoints through filterTable.

There is also an interesting concept called back up endpoints. The messages are routed to these back up endpoints when the main client WCF service endpoint routing fails for some reason. There can be multiple backup endpoints specified and the failover will happen in the provided order.

       <backupList name="GreetingBackupEPList">
              <add endpointName="BackupGreetingService1"/>
              <add endpointName="BackupGreetingService2"/>
              <add endpointName="BackupGreetingService3"/>

This back up list can be linked to the filterTable.

I hope this article provided a good step-in for the WCF 4.0 Routing Service feature. There is still much more to explore and experiment.

Happy reading!

About the Author

V.N.S Arun

I work for an MNC in Bangalore, India. I am fond of writing articles, posting answers in forums and submitting tips in dotnet. To contact me please feel free to make use of the "Send Email" option next to the display name.

Related Articles


  • Steps to Consume WCF routing Service

    Posted by Arun Tripathy on 03/26/2015 10:26pm

    Hi Arun.In case of normal way of WCF service consumption , at client side, Service Contract, Data Contract etc are available. But in case of WCF routing service how to interact with service contract , DataContracts etc through the in-built IRequestReplyRouter contract of Router Service.

  • Fake Oakley Radar free shipping

    Posted by fmeapjqtn on 07/04/2013 10:41pm

    FakE OaklEyS ,Oakley fashion sport sunglasses. Led the international status like a sports brand, as well as a beautiful fashion appearance of sunglasses. The sports sunglasses, sunglasses to help promote explore the amount with the market, also are developed using shatterproof degree lens, in addition to the face according to the tailor-made cheap Oakley sunglasses. For style forward even Oakley at the pinnacle. Oakley use of the latest model generated glasses. Oakley shade in the application can be quite a large celebrity list. FAke OAkley Big TAco ,The sale of Oakley sunglasses will not be simply a tool to prevent sunshine, and also literally role on the decorative surface. Fresh dawn in the shadow with the sun, enjoy some of Dennis to offer an answer to acquire virtually any obsolete temporary workers, you will find outside play Oakley jaw, to be able to have a strange John Coast Recreation sunshade. Premium quality and technology experts, each design is obvious this is a perfect brand, if you like a good and effortlessly cool finish in your look. Another style versus the other necessities, improve support services needs, shops want to offer the important modifications in their future Oakley sun tone. cheap oakley sunglasses ,Oakley sports sunglasses better sunglasses sold to discover. You'll find a framework and coated lenses to adjust to every face type. Date night, a copy of jewelry function to get a wide range of the style industry praise, Sales and affordable because they are designed for just a great alternative to platinum, gold, and also other jewelry Oakley sunglasses. fake ray ban sunglasses ,Note are unable to see ultraviolet illumination, the approval Oakley sun screen lotion, to lose the sun's ultraviolet radiation power, in particular, is a bit more harmful ultraviolet illumination, wil attract. A really professional sports mirror using a unique personality, the full selection of functionality to win the respect of various celebrities around the world. longchamp le pliage ,Bending can change the symptoms contours with the lenses, causing optical distortion, therefore you still find the optimized comfort in order to conform to an adaptable frame design. Whether you'll want to modify?? Up your eyes to adapt to your sunglasses, which may be produced by the identical company, it may guarantee exactly the same service quality, mixing style and practicality. Are looking at the key items for your sunglasses, polarized contacts is found throughout the sunglasses warehouse supplies, even if you're not a fashionable pursuit.

  • Smart Device to WCF Router connection not working

    Posted by Leela Kumar on 03/11/2013 09:43pm

    Hi , Am working in C# smart device (Mobile Apps).this mobile apps connecting to Wcf Router and when i am pass request to Wcf Router ,Its throw Error Message to "Not establish connection to network..."

  • Very nice..

    Posted by Malte Baden Hansen on 12/19/2012 12:58pm

    Very nice article. I like your keep it simple approach, many tutorials only add a single client to the routing config. Which seems a bit pointless unless its to bridge different protocols. I do however really miss an explaination to what exactly that configuration does when the wcf router is running.

  • Need more information

    Posted by SUJITH on 06/07/2012 10:38am

    you are not specified how to access routing service on the client please include that also. Otherwise a user new wcf does not understand anything from this. He will stuck up with adding this on the the routing service. Please add the following details also 1. WCF Services that are configured in the section. 2.How to consume these through routing services

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date