我如何在温莎城堡WCF设施中注册我的所有服务 [英] How can I register all my services with castle windsor wcf facility

查看:98
本文介绍了我如何在温莎城堡WCF设施中注册我的所有服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我可以像这样注册一项服务.

Basicly I can register one service like this.

Container.Register(Component.For<IMyService>()
                       .AsWcfClient(new DefaultClientModel() { 
                            Endpoint = WcfEndpoint
                                   .BoundTo(new NetNamedPipeBinding())
                                   .At("net.pipe://localhost/MyService") })
                       .LifeStyle.PerWebRequest);

但是我不知道如何用相似的配置注册我的所有服务.

But I could not figure out how to register all my services with similar configuration.

我希望运行的是这个...

the thing I was hoping to run is this...

Container.Register(
    AllTypes.FromAssemblyNamed("My.Server.MyContracts")
        .Pick().If(x => x.Name.EndsWith("Service"))
        .Configure(configurer => configurer.Named(configurer.Implementation.Name)
                .AsWcfClient(new DefaultClientModel
                {
                    Endpoint = WcfEndpoint.BoundTo(new NetNamedPipeBinding())
                    .At(string.Format("net.pipe://localhost/{0}", configurer.Named(configurer.Implementation.Name)).Substring(1))
                }))
            .LifestylePerWebRequest()
        );

如何将所有服务注册为wcf客户端?

How can I register all services as wcf client?

推荐答案

使用Windsor 3.0,您只需要使用 Types 而不是 AllTypes ,以便它注册服务界面并为您生成客户端动态代理,如下所示:

Using Windsor 3.0, you just need to use Types instead of AllTypes so that it registers the service interface and generates a client side dynamic proxy for you like so:

Container
    .Register(
        Types
            .FromAssemblyNamed("My.Server.MyContracts")
            .Pick()
            .If(x => x.Name.EndsWith("Service"))
            .Configure(
                configurer => configurer.Named(configurer.Implementation.Name)
                                  .AsWcfClient(new DefaultClientModel
                                                   {
                                                       Endpoint = WcfEndpoint
                                                           .BoundTo(new NetNamedPipeBinding())
                                                           .At(string.Format(
                                                                       "net.pipe://localhost/{0}",
                                                                       configurer.Name.Substring(1)))
                                                   }))
            .LifestylePerWebRequest());

这篇关于我如何在温莎城堡WCF设施中注册我的所有服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆