WCF服务库托管作为Windows服务使用Castle.Windsor 3.0问题 [英] WCF Service Library hosted as a Windows Service using Castle.Windsor 3.0 issue

查看:170
本文介绍了WCF服务库托管作为Windows服务使用Castle.Windsor 3.0问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的主机WCF服务库中的Windows服务。虽然会被传达给另一个wcfservice在本地网络。



我在寻找最近的,最新的最新文档有很大的困难,或者帮助来配置解决方案此目的。任何人都可以提出建议:



一)什么对这种连接的首选终点? (其他WCF服务使用的是basicHttpBinding的托管) - 这本身很适合通过劫持在Global.asax配置城堡容器。但是,在托管Windows服务这种解决方案意味着我不再有机会获得一个Global.asax中!



二)如何温莎城堡配置为使用DI使用这一解决方案?目前,我看着它挂接到App_Code文件的AppInitilize()方法,以及一些其他的,不再有效的解决方案。



目前的解决方案架构:



*核心(C#类库)



*服务(C#类库)



* WCF SERVICS(WCF服务库)



* Windows服务(Windows服务项目)



有关AppInitilize()示例代码[其中犯规目前似乎工作]:

 公共类WindsorConfiguration 
{
公共静态IWindsorContainer集装箱{搞定;私人集; }

公共静态无效AppInitialize()
{
{
集装箱=新WindsorContainer()
.AddFacility< WcfFacility>()
。.Register(Component.For< IVirusCheckService>()ImplementedBy< VirusCheckService>()
.LifeStyle.Transient
.AsWcfService(新DefaultServiceModel()
.AddBaseAddresses(HTTP://本地主机:8080 /则将MyService)
.AddEndpoints(WcfEndpoint.BoundTo(新basicHttpBinding的())
.AT(基础))
.PublishMetadata(O => o.EnableHttpGet() )))
.Register(Component.For&所述; ILoggingService>()ImplementedBy&所述。LoggingService>());
}
}


解决方案

要答题 (排序) - 我不认为这是一个首选的方法 - 它真的只是取决于你希望你的服务是可用的。我主持的net.tcp(我怀疑这是在Windows服务环境中最常见的,但我猜),webhttp,basichttp和wshttp服务的所有从Windows服务中的罚款。到 ...



所以我这样做(也许这只是一种风格的东西,但它为我的作品)的方式是,我有一个常规的Windows服务,在程序主我引导容器(这样的东西,你会做内部App_Start全球ASAX),我有应用程序的不同部分我想安装(顺带安装,一般在WCF我分裂出的合同到自己组装并加以实施的窗口服务组件内,或在一个单独的程序,如果我需要托管在多个地方相同的服务)。



一旦容器自举,我再解决从容器中ServiceBase,并把它交给的 ServiceBase.Run 静态方法。这样,我的服务能对其他任何在容器中注册的依赖(这是我将永远通话时解决在容器上唯一的地方,但我认为这是很有道理在这种情况下)。



我不知道你希望你的服务做的比托管的WCF服务,也许没有其他别的什么,但是这是一个有点框架,让你去所以这里这是...

 静态类节目
{
静态无效的主要()
{
ServiceBase.Run(CreateContainer()解决&所述。ServiceBase>());
}

私有静态IWindsorContainer CreateContainer()
{
变种集装箱=新WindsorContainer();
container.Install(FromAssembly.This());
返回容器中;
}
}

公共类ServicesInstaller:IWindsorInstaller
{
公共无效安装(IWindsorContainer容器,IConfigurationStore店)
{
容器
.AddFacility< WcfFacility>(F =>
{
f.CloseTimeout = TimeSpan.Zero;
})
.Register(
组件
。对于< IVirusCheckService>()
.ImplementedBy< VirusCheckService>()
.LifeStyle.Transient
.AsWcfService(新DefaultServiceModel()
.AddBaseAddresses( HTTP://本地主机:8080 /则将MyService)
.AddEndpoints(WcfEndpoint.BoundTo(新basicHttpBinding的())
.AT(基础))
.PublishMetadata(O => o.EnableHttpGet())),
组件
&。对于LT; ServiceBase>()
.ImplementedBy<&为MyService GT;());
}
}

注:为MyService类只是一个常规的Windows服务类(你可以用一个视觉工作室为您生成当你去文件|新| Windows服务,如果你喜欢) - 我还没有表现出它,因为它可以只是一个空的实施


I am wanting to host my WCF Service Library in a windows service. Although it will be communicating to another wcfservice over a local network.

I am having great difficulty in finding recent, up-to-date documentation or help to configure the solution for this purpose. Can anyone advise:

a) What the preferred endpoint for this kind of connection? (The other WCF service is hosted using a basicHttpBinding) - this in itself lends itself well to configuring the Castle container through hijacking the global.asax. However, hosting this solution in a windows service means i no longer have access to a global.asax!

b) How to configure Castle Windsor to use DI with this solution? Currently I've looked into hooking it into the AppInitilize() method of App_Code, and some other, no longer valid solutions.

Current Solution architecture:

*Core (C# Class Library)

*Services (C# Class Library)

*WCF Servics (WCF Service Library)

*Windows Service (Windows Service Project)

Sample Code for AppInitilize() [ which doesnt currently seem to be working ]:

public class WindsorConfiguration
    {
        public static IWindsorContainer Container { get; private set; }

        public static void AppInitialize()
        {
            {
                Container = new WindsorContainer()
                    .AddFacility<WcfFacility>()
                    .Register(Component.For<IVirusCheckService>().ImplementedBy<VirusCheckService>()
                                  .LifeStyle.Transient
                                  .AsWcfService(new DefaultServiceModel()
                                                    .AddBaseAddresses("http://localhost:8080/MyService")
                                                    .AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding())
                                                                      .At("basic"))
                                                    .PublishMetadata(o => o.EnableHttpGet())))
                    .Register(Component.For<ILoggingService>().ImplementedBy<LoggingService>());
            }
        }

解决方案

To answer question a (sort of) - I do not think there is a "preferred" approach - it really just depends how you want your service to be available. I've hosted net.tcp (I suspect this is the most common in a windows service environment but I am guessing), webhttp, basichttp and wshttp services all fine from inside a windows service. Onto b...

So the way I do this (and maybe this is just a style thing but it works for me) is that I have a regular windows service and in the program main I bootstrap the container (so stuff that you would do inside App_Start in global asax) and I have installers for the different parts of the application I want to install (incidentally, generally in WCF I split the contracts out into their own assembly and implement them inside the windows service assembly, or in a separate assembly if I need to host the same service in multiple places).

Once the container is bootstrapped, I then resolve the ServiceBase from the container and give it to the ServiceBase.Run static method. This way my service can have dependencies on whatever else is registered in the container (this is the only place I would ever call Resolve on the container but I think it is justified in this circumstance).

I don't know what else you want your service to do other than hosting WCF services, maybe nothing, but this is a bit of framework to get you going so here it is...

static class Program
{
    static void Main()
    {
        ServiceBase.Run(CreateContainer().Resolve<ServiceBase>());
    }

    private static IWindsorContainer CreateContainer()
    {
        var container = new WindsorContainer();
        container.Install(FromAssembly.This());
        return container;
    }
}

public class ServicesInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container
            .AddFacility<WcfFacility>(f =>
                                          {
                                              f.CloseTimeout = TimeSpan.Zero;
                                          })
            .Register(
                Component
                    .For<IVirusCheckService>()
                    .ImplementedBy<VirusCheckService>()
                    .LifeStyle.Transient
                    .AsWcfService(new DefaultServiceModel()
                                      .AddBaseAddresses("http://localhost:8080/MyService")
                                      .AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding())
                                                        .At("basic"))
                                      .PublishMetadata(o => o.EnableHttpGet())),
                Component
                    .For<ServiceBase>()
                    .ImplementedBy<MyService>());
    }
}

NOTE: The MyService class is just a regular Windows service class (you can use the one visual studio generates for you when you go file | new | windows service if you like) - I have not shown it because it can just be an empty implementation.

这篇关于WCF服务库托管作为Windows服务使用Castle.Windsor 3.0问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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