3

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

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

但我不知道如何用类似的配置注册我的所有服务。

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

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 客户端?

4

1 回答 1

4

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

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());
于 2012-01-10T08:39:58.510 回答