Hi guys,

I posted this question on Stack Overflow, and havent received a
response, so I thought I would post it where all the Castle brains are -
and include a link just in case someone wants to share the answer there
too:
http://stackoverflow.com/questions/4823901/castle-windsor-wcf-client-ser
vice-registration-based-on-convention

*snip*

Hi Team!

I have a client-server application, which intercommunicate via WCF. They
also both use Castle Windsor for resolving dependencies.

My goal, is to completely avoid having to explicitly register server, or
client WCF endpoints. I have achieved the server-side by 'convention'
using the following code
// registers all services which implement exactly 1 [ServiceContract]
_windsorContainer.Register(
AllTypes.FromThisAssembly().IncludeNonPublicTypes().Where(
    t => 1 == (from i in t.GetInterfaces() where
i.IsDefined(typeof(ServiceContractAttribute), true) select i).Count())
    .Configure(c => c.LifeStyle.PerWcfSession()
    .ActAs(new DefaultServiceModel().AddEndpoints(
         WcfEndpoint.BoundTo(new NetTcpBinding())
             .At("net.tcp://" + LocalAddress.ToString() + ":7601/" +
c.ServiceType.Name),
         WcfEndpoint.FromEndpoint(new UdpDiscoveryEndpoint())
            ))

    ).WithService.Select(
    (Type type, Type[] baseTypes) => from i in type.GetInterfaces()
where i.IsDefined(typeof(ServiceContractAttribute), true) select i
    )
);

This code will find all classes in the current assembly, and any which
implement a service-contract interface (identified by the
ServiceContract attribute) will be registered (with UDP discovery) at
the address
"net.tcp://localhost:7601/[service-contract-interface-name]".

Now, I just want the client-side of the equation.

Typically, to use castle to generate client-proxies for WCF contracts,
the following code will work:
var model = new DefaultClientModel
{
    Endpoint = WcfEndpoint.ForContract<IServiceContract>().BoundTo(new
NetTcpBinding()).Discover(typeof(IServiceContract))
};

container.Register(
    Component.For<ChannelReconnectPolicy>(),
    Castle.Facilities.WcfIntegration.WcfClient.ForChannels(model),
);

What I want, is for Castle to do this kind of registration for all
'service-contract' interfaces in a given assembly - however the AllTypes
helper seems to return only classes, not interfaces (which I guess makes
it an 'AllClasses', not 'AllTypes'!)... Can Castle do this, and what is
the syntax? Krzysztof? (help!)

Thanks!

Adam Langley

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to