2

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?

Joe
  • 122,218
  • 32
  • 205
  • 338
  • Why not just use the proxy class constructor that takes an `EndPointAddress`? – John Saunders Sep 15 '10 at 18:28
  • I can't achieve what I want using the proxy class constructor (actually in my case a ChannelFactory constructor) because at that point I don't yet know what address to use. – Joe Sep 15 '10 at 18:39
  • 1
    How can you not know the address in the time of creating proxy? – Ladislav Mrnka Sep 15 '10 at 19:11
  • My goal is to have endpoint behavior elements in the app config file that define the changed addresses of my services. And when I construct my ChannelFactory I don't yet have access to the endpoint and its behaviors. – Joe Sep 15 '10 at 19:37
  • Joe -- did you ever find the correct implementation to acheive your goal? – Jennifer Zouak Dec 01 '11 at 20:21
  • @Jennifer, no I wasn't able to achieve this without modifying the client code. Once I accepted I had to modify the client code, I could pass the address to the proxy class constructor. – Joe Dec 01 '11 at 21:34

1 Answers1

2

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
  • 360,892
  • 59
  • 660
  • 670
  • 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 Sep 15 '10 at 19:47