Click here to Skip to main content
13,899,955 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 28 Sep 2011
Licenced CPOL

Router Service in WCF 4.0

, 28 Sep 2011
Rate this:
Please Sign up or sign in to vote.
Router represents a logical connection between inbound and outbound endpoints


MS.NET 4.0 Technology represents a foundation technology for metadata driven model applications. This article focuses on one of the unique components from the WCF 4 model for logical connectivity called Routing Service. We will try to extend its usage for enterprise application driven by metadata stored in the Runtime Repository. The basic idea behind routing service is to route messages based on message content. It is also a good tool to design a load balancer in your enterprise application architecture. I am going to cover a simple "how to design a simple routing service".

WCF Routing Service allows the following Message Exchange Pattern (MEP) with contract options:

  • OneWay (SessionMode.Required, SessionMode.Allowed, TrasactionFlowOption.Allowed)
  • Duplex (OneWay, SessionMode.Required, CallbackContract, TrasactionFlowOption.Allowed)
  • RequestResponse (SessionMode.Allowed, TrasactionFlowOption.Allowed)

In addition to the standard MEPs, the Routing Service has a built-in pattern for Multicast messaging and Error handling. The following image describes the complete in & out flow.

The router process is very straightforward, where the message received by inbound endpoint is forwarding to the outbound endpoint or multiple endpoints based on the prioritized rules represented by message filter types. The evaluation rules are started by highest priority. The router complexity depends on the number of inbound and outbound endpoints, type of message filters, MEPs and priorities.

Note that the MEP pattern between the routed inbound and outbound endpoints must be the same, for example: the OneWay message can be routed only to the OneWay endpoint, therefore for routing Request/Response message to the OneWay endpoint, the service mediator must be invoked to change the MEP and then back to the router.

Using the Code

The following code snippet describes how to configure router service endpoint.

<service name="System.ServiceModel.Routing.RoutingService" 

              <add baseAddress="http://[your service address]/RoutingService/Router" />
















Here, we will configure the service which will listen to the inbound call to router:



        address="http://[your service address]/patientmanagementservice.svc" 





        address="http://[your service address]/clinicalspatientmanagementservice.svc"




In the below config section, first we will declare the filter in <filters> section. In this, we will define the filter type and filter data.

In <filterTables> section, we will create filter table and here we will map the above created filter to the actual service (which is going to handle this type of incoming request).

        <filter name="PatientManagement_Filter" filterType="EndpointName" 

			filterData="PatientManagement_Router" />
        <filter name="ClinicalsPatientManagement_Filter" 

	    filterType="EndpointName" filterData="ClinicalsPatientManagement_Router"/>

        <filterTable name="RoutingService_FilterTable">
           <add filterName="PatientManagement_Filter" 

			endpointName="PatientManagement_Client" />
           <add filterName="ClinicalsPatientManagement_Filter" 


Finally we will host the service, here I am using a sample console based application for hosting this service.

using(var serviceHost = new ServiceHost
    var endpointCounter = 0;
    Console.WriteLine("Routing Service configured, opening........");
    Console.WriteLine("\r\nRouting Service is now running.....
    	and listening at following addresses");
    foreach (var endPoint in serviceHost.Description.Endpoints)
        Console.WriteLine("\r\n" + endpointCounter + ".) 
        	" + endPoint.Address.ToString());
    Console.WriteLine("\r\nPress <ENTER> to terminate router.");


The information in this article is provided “AS IS” with no warranties, and confers no rights. This article does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.

All data and information provided in this article is for informational purposes only. I makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...


Comments and Discussions

GeneralSource code ??? Pin
Pardhac20-Dec-12 20:36
memberPardhac20-Dec-12 20:36 
BugImage link is broken Pin
Thiago_Lima4-Sep-12 6:16
memberThiago_Lima4-Sep-12 6:16 
GeneralMy vote of 2 Pin
Anders Lybecker3-Oct-11 19:17
memberAnders Lybecker3-Oct-11 19:17 
GeneralMy vote of 4 Pin
Wooters28-Sep-11 5:35
memberWooters28-Sep-11 5:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190306.1 | Last Updated 28 Sep 2011
Article Copyright 2011 by {var name = Amit}
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid