tags:

views:

177

answers:

3

I am building an single application that uses WCF to call out to multiple external endpoints. All of the remote endpoints are identical except for the URI. I would like to treat them as a pool: add and remove endpoints through configuration and have the application understand what to do.

My original plan was to define one endoint in the app.config, then iterate over my list of endpoints and update client.Endpoint.Address on the fly to point to the right place. Unfortunately, that property is read-only, rendering that plan unworkable.

I'm a little bit stumped here. Any suggestions on how I might accomplish this?

+1  A: 

How to: Create a Service Endpoint in Code shows you how to manage service endpoints in code rather than configuration.

Jason Punyon
A: 

Have you tried a separate name that is passed in to the client constructor?

          <endpoint address="http://localhost:18000/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="BasicHttpBinding_IMyService" />
          <endpoint address="http://localhost:18001/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="MyService_Secondary" />
          <endpoint address="http://localhost:18002/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="MyService_Tertiary" />
Lucas B
I did consider that and it is my fallback position, but that seems to require a code change every time I add another server to the pool.
Jacob
A: 

Store the end point addresses in a DB table and use Jason's suggestion for creating end points in code. When a new endpoint shows up you just add another row to the table and force the service to re-query the endpoint table.

How to: Create a Service Endpoint in Code http://msdn.microsoft.com/en-us/library/ms731080.aspx

MadMoai