How to change the address of a channel from the ChannelFactory (WCF)
I am trying to create a smart proxy so if a call开发者_如何学JAVA to one address doesn't work, the proxy automatically goes to the second address. To do this I am using Unity with ChannelFactory
. I am able to intercept the calls on the Channel that I get back from ChannelFactory.CreateChannel()
, but I am not able to tell my Channel to close and point to a new address.
I don't want to re-create the channel, I just want to re-configure it. Is it possible? I am not able to do this with IChannel
, ICommunicationObject
or IClientChannel
... I can only get the address as read only but not change it.
(I know this is possible with WCF Routers, but I am trying do solve the single point of failure to the router).
Once you have a channel, you cannot change its address later on - but when you create the channel from your factory, you can supply an endpoint address to use:
public TChannel CreateChannel(EndpointAddress address)
See the MSDN docs for the CreateChannel method for more details.
So you can do something like this:
EndpointAddress addr = new EndpointAddress("http://yourserver:7777/YourService");
IYourService client = factory.CreateChannel(addr);
If you want to change it, you just need to create a new channel instance from your factory, and specify a different endpoint address.
精彩评论