Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern for WCF client switching and failover capabilities?

Tags:

c#

wcf

I'm looking to identify a best practice or often used design pattern for WCF communication allow communication to occur and fail over to another service or local service of information if the WCF (or initial service exists)

I'm not sure this makes much sense so let me give an example. I'd like this agent to be able to connect to a wcf service and (hopefully) expose the contract methods to the caller (UI/BO, etc) so that this object can call these methods, the agent attempts to contact a primary service (likely WCF), if it fails connect to a secondary service.

Ideally all the failover and reconnection logic would be contained in the agent.

Is there a design pattern that encapsulates a "switching wcf client with failover"?
Maybe not a design pattern, anyone recommend a decent approach?

like image 684
Beta033 Avatar asked Sep 29 '10 18:09

Beta033


3 Answers

I would do it like this:

  • The configuration of the client has a single reference to the service
  • The client has a proxy class for communicating with the service
  • In the proxy class there is a try catch
  • In the try set the address to that of the main service and call the service
  • If it fails you will enter the catch block, here you can set the address to the backup service and call it.
like image 63
Shiraz Bhaiji Avatar answered Nov 13 '22 22:11

Shiraz Bhaiji


Juval Lowy has a great article on the WCF Discovery protocol: http://msdn.microsoft.com/en-us/magazine/ee335779.aspx

In a nutshell, this leverages UDP's broadcast mechanism to discovery the location of services that implement a specified interface. So, the pattern could be that when a client comes on line it will discover the location of a service and for the life of that client and service they will communicate back and forth. In the event that the service provider were to become unavailable the client can revert to discover another service and then continue.

This pattern allows the administrator to setup endless backup services with minimal configuration on the client.

like image 3
Markis Avatar answered Nov 13 '22 22:11

Markis


I currently run things as Shiraz describes. I have a ServiceCaller class and a Call method which wraps a delegate that is the actual call on the service. Before invoking the delegate, I can do some other things as well as wrap it in a try catch and centralise the error handling.

http://www.lukepuplett.com/2010/07/adding-useragent-to-wcf-clients.html

In the future I plan to use NLB or MSMQ. Why? Well, failover is very closely related to load balancing, and so I'd start with NLB.

Try these articles;

http://msdn.microsoft.com/en-us/library/ms730128.aspx

http://www.devproconnections.com/print/net-framework2/load-balancing-and-scaling-your-wcf-services.aspx

Good luck, let us know how you get on.

Luke

like image 2
Luke Puplett Avatar answered Nov 13 '22 23:11

Luke Puplett