tags:

views:

43

answers:

1

I want to dynamically change the address of a WCF service called from my client based on custom information in the client's application configuration file.

My first attempt was to create an endpoint behavior, and implement the IEndpointBehavior.Validate method, implemented something like the following:

void IEndpointBehavior.Validate(ServiceEndpoint endpoint)
{
    ... endpoint.Address = new EndpointAddress(...);
}

This method is called before the client attempts to connect, and appears to successfully change the endpoint address. However the WCF infrastructure appears to still attempt the connection using the original address.

Is there any way to achieve this using an endpoint behavior or some other WCF extension point?

+1  A: 

I think the problem is the base functionality of CommunicationObject. When the communcitation object moves to Opened state it cannot change anything. So if your communication object (Channel or ChannelFactory) is already in Opened state you can't change address.

Ladislav Mrnka
That sounds plausible. Presumably IEndpointBehavior.Validate is executed too late, after the ChannelFactory is opened. I'm wondering are there any other extension points that allow me to attach behavior to the endpoint before the ChannelFactory is opened, so I can achieve my goal.
Joe