代码之家  ›  专栏  ›  技术社区  ›  Khash

仅使用代码在IIS外使用Castle Windsor托管WCF服务

  •  1
  • Khash  · 技术社区  · 15 年前

    我正在尝试使用Castle Windsor 2.5(.NET 4)在控制台应用程序中托管WCF服务,代码如下:

            new WindsorContainer()
                .AddFacility<WcfFacility>()
                .Register(
                Component.For<IMyService>().ImplementedBy<MyService>()
                              .ActAs(new DefaultServiceModel()
                                                 .AddEndpoints(
                                                 WcfEndpoint.BoundTo(new BasicHttpBinding()).At("http://localhost:1010/MyService"),
                                                 WcfEndpoint.BoundTo(MetadataExchangeBindings.CreateMexHttpBinding()).At("http://localhost:1010/MyService/mex"))
                                             ));
    

    然而,这似乎不起作用(没有抱怨,但WcfTestUtil看不到服务)。

    我遗漏了什么吗?

    3 回复  |  直到 15 年前
        1
  •  3
  •   Khash    15 年前

    在Castle Google Groups上发布了这个问题,得到了更好的反馈,但既然如此,Google比Google Groups更友好(讽刺!),我将在这里为其他人发布答案的链接: http://groups.google.com/group/castle-project-users/browse_thread/thread/d670d8f1d7aae0ab

        2
  •  1
  •   Mike Chamberlain JaredPar    12 年前

    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container
            .AddFacility<WcfFacility>()
            .Register(
                Component.For<ICoreService>()
                .ImplementedBy<CoreService>()
                .AsWcfService(new DefaultServiceModel()
                    .AddBaseAddresses("http://localhost:1000/core")
                    .AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding()))
                        .PublishMetadata(o => o.EnableHttpGet()))
        );
    }
    
        3
  •  1
  •   Frank    10 年前

    我正在使用wcfFacility 3.3.0并在windows服务中托管wcf服务dll 这是我的工作组件注册:(add Hosted())

    public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.AddFacility<LoggingFacility>(f => f.UseLog4Net());
    
            container
                .AddFacility<WcfFacility>(f =>
                {
                    f.CloseTimeout = TimeSpan.Zero;
                });
    
    
            string baseAddress = "http://localhost:8744/TVIRecorderWcfService/";
    
            container.Register(
    
                Component
                    .For<ITVIRecorderWcfService>()
                    .ImplementedBy<TVIRecorderWcfService>()
                    .AsWcfService(
                    new DefaultServiceModel()
                        .AddBaseAddresses(baseAddress)
                        .Hosted()
                        //publish metadata doesn't work, have to do differently
                        //.PublishMetadata(x => x.EnableHttpGet()).Discoverable()
                        .AddEndpoints(WcfEndpoint
                            .BoundTo(new BasicHttpBinding()))
                            //.PublishMetadata(x=>x.EnableHttpGet()).Discoverable()
                            ).LifestyleSingleton()
                            ,
    
                Component
                    .For<ServiceBase>()
                    .ImplementedBy<TVIRecorderService>());
        }
    

    要被WcfTestClient util看到,服务必须发布其serviceMetadata

    var binding = MetadataExchangeBindings.CreateMexHttpBinding();
    var mexAddress = "http://localhost:8744/TVIRecorderWcfService/mex";
    var behaviour = new ServiceMetadataBehavior() {HttpGetEnabled = true};
    
    
    serviceHost.Description.Behaviors.Add(behaviour);
    serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), binding, mexAddress);