views:

133

answers:

2

How do I use the Castle WcfFacility and have it use the standard Wcf config file settings?

If I register like so:

container.Register(
AllTypes.Pick()
    .FromAssemblyNamed("{ServicesAssembly}") // <-- service assembly here
    .If(type => type.Name.EndsWith("Service"))
    .WithService.FirstInterface()
    .Configure(configurer => configurer.LifeStyle.Transient)
    .Configure(configurer => configurer.Named(configurer.Implementation.Name))
    .Configure(configurer => configurer.ActAs(new DefaultServiceModel()))
);

I receive the following error:

Service '{name}' has zero application (non-infrastructure) endpoints.

If I leave off:

.Configure(configurer => configurer.ActAs(new DefaultServiceModel()))

it seems as though the behaviors in the config are ignored.

What is the correct usage here?

A: 

You're almost there.

You need this:

.ActAs(new DefaultClientModel(WcfEndpoint.FromConfiguration( <<key In Configuration>> )));
Krzysztof Koźmic
Thanks... but :) --- this is the service side (DefaultServiceModel). How would one do it on the server side? Also, what 'key' is that (perhaps the name of the service)?
Eben Roux
key is the configuration key, most likely type name, unless you specified `ConfigName` on `ServiceBehaviorAttribute` to somewhere else. Can't `DefaultServiceModel` be used that way as well?
Krzysztof Koźmic
Nope. There is an AddEndpoints method but using Wcf.FromConfiguration results in an error: The ServiceEndpoint for a ServiceHost cannot be created from an endpoint name.
Eben Roux
hmm, that's interesting. I suggest you bring this up on Castle users discussion group. Maybe this is a missing feature...WCF Facility is not released yet so it may not have everything that is required.
Krzysztof Koźmic
+1  A: 

OK, figured it out :)

I register like so:

container.Register(
AllTypes.Pick()
    .FromAssemblyNamed("{ServicesAssembly}") // <-- service assembly here
    .If(type => type.Name.EndsWith("Service"))
    .WithService.FirstInterface()
    .Configure(configurer => configurer.LifeStyle.Transient)
    .Configure(configurer => configurer.Named(configurer.Implementation.Name))
    .Configure(configurer => configurer.ActAs(new DefaultServiceModel().Hosted()))
);

The Hosted() is there to indicate that I am hosting the services; else is seems as though the WCF Facility will try to host them, resulting in port conflicts.

So the problem was that the name of the service in the config file has to be the full type name of the implementation. If not one receives an error stating something along the lines of no endpoints defined. So the service name is not the same as the name specified in windsor.

Eben Roux