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?
I would do it like this:
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With