Sai
Sai

Reputation: 675

Castle windsor wcf facility - add clients through config file

I'm using Castle windsor wcf facility for self hosting my services. On the client side I would like to use wcf facility again for consuming them. I want to register the services at client side dynamically by looping getting all the operationcontracts and register them through code but get endpoint configuration from a config file.

Most of the examples I saw on internet are using code to register them. I cannot use that as my client want more flexibility for manipulating the config file if and when needed. below is the code I came up with but it fails to read the configuration of client endpoints from config file.

  container.Register( Classes
                  .FromAssemblyContaining<IXXX>()
                  .Pick()
                  .If(x => x.IsClass && HasServiceContract(x))
                  .Configure(c => c.AsWcfClient().LifeStyle.PerWcfOperation()));

Please advise.

Thanks in advance

Sai

Upvotes: 1

Views: 1006

Answers (1)

wexman
wexman

Reputation: 1295

Here's how I'm doing it:

container.Register(
   Component.For<ISomeService>()
      .AsWcfClient(WcfEndpoint.FromConfiguration("*"))
);

The "*" is actually a wildcard for an endpoint name. You could as well specify a named endpoint, but using the wildcard is my preferred way (it will then pick any endpoint with a matching service interface).

Please note that LifeStyle.PerWcfOperation only works for server side components and cannot be used on a wcf client (well maybe it can, but I guess it won't do anything).

Upvotes: 6

Related Questions