During my Indigo talk at the HDC, I was asked about load balancing to another endpoint if your current proxy endpoint is down. I took a look at this problem during lunch today, and this is what I did to solve it:
If you created your proxy using svcutil, you will have a local copy of the service interface. In my second demo, I had the IEightBallService interface under my EightBallProxy.cs file. The main proxy class, EightBallServiceProxy, inherits from System.ServiceModel.ClientBase<T> and implements the generated IEightBallService interface.
The EightBallServiceProxy class also encapsulates a System.ServiceModel.ChannelFactory<T>. Which in turn, exposes a ServiceEndpoint through the ChannelFactory<T>.Description.Endpoint property. So, now that I’ve taken you around the make up of the proxy class, I will show you how you can update the endpoint property of the proxy.
The ChannelFactory<T> class has a constructor that allows for the configuration name of an endpoint in the config file. Using this constructor, the Description.Endpoint property is configured with the settings found in the config file. Now, all we have to do is take the Endpoint.Address and Endpoint.Binding for the EightBallServiceProxy and set them to the values of the new ChannelFactory<T>.Description.Endpoint.
Take a look at this code:
// Creates a proxy using the netTcp configuration name for the endpoint
EightBallServiceProxy proxy = new EightBallServiceProxy("netTcp")
// Change the endpoint to the endpoint configuration for "netPipes"
RedirectProxy<IEightBallService>("netPipes", proxy);
// Swap the values for the endpoints from the new factory and existing proxy
private void RedirectProxy<T>(string configName, ClientBase proxy) where T:class
{
ChannelFactory factory = new ChannelFactory<T>(configName);
proxy.Endpoint.Address = factory.Description.Endpoint.Address;
proxy.Endpoint.Binding = factory.Description.Endpoint.Binding;
}
Hope this code snippet helps!