Friday, June 18, 2010

WCF 4.O Routing Service : Failover

In my last post i wrote about WCF 4.0 routing services and various scenarios where it can be used. Failover is one the scenario where routing services comes very handy, to my surprise last week I had an incident when few of my colleague asked how is it possible automatically (apnae aap kaise ho sakta hai). I do not blame that may be they are not aware of this beautiful add on feature in WCF 4.0. Just few configuration and you are done. Download Source Code

If you are new to WCF routing services I recommend reading this.

You just need to create a backuplist node under routing node in wcf configuration file as shown in the given below picture. Add you back up endpoint there and there you go




Steps to run the and test the source code. (You need VS2010 to run and test this application)

Source code contains

1) Two normal WCF services : Air service ( Air.svc) and Road Service (RoadService.svc)
2) One Routing Service : RoutingService.svc
3) Console Client: This call the routing service.

To test this application first run all the three services by right clicking and selecting view in browser for each of these files i.e Air.svc, RoadService.svc and RoutingService.svc. As you can see in the configuration of routing service RoadService is your primary endpoint  which means all the request should go to road service which you can verify by seeing the out put (in console client application) as “Travel by Road”. Now You stop the RoadService to simpulate the failover scenario, you will see that requests will automatically be going to AirService (which is your backup service incase of failover) which again you can verify y seeing the output.

In real business failover scenario these two service endpoint will be pointing to the same service, but here they are different services (Road and Air) just to test the failover.

No comments: