简体   繁体   English

WCF集成工具和自托管服务

[英]WCF Integration Facility and Self-Hosted Services

I'm self-hosting several services where I do this to register the service: 我自己托管了几个服务,我这样做是为了注册服务:

host = new ServiceHost(typeof(MyService));
host.Open();

Behind the scenes, wcf instantiates my service via the default constructor. 在幕后,wcf通过默认构造函数实例化我的服务。

Is it possble to use the WCF Integration Facility of Castle Windsor to get WCF to call on Windsor to create the service when I am self-hosting? 是否有可能使用Castle Windsor的WCF集成工具让WCF在我自托管时调用Windsor来创建服务?

The example seems shows IIS hosted services where the 1st line of the MyService.svc file looks like: 该示例似乎显示了IIS托管服务,其中MyService.svc文件的第一行如下所示:

<%@ServiceHost language=c# Debug="true" 
     Service="Microsoft.ServiceModel.Samples.CalculatorService" 
     Factory=WindsorServiceHostFactory%>

where presumably a factory is used by wcf to instantiate the service instance. 据推测,wcf使用工厂来实例化服务实例。

This may be helpful: 这可能会有所帮助:
How to host a WCF service that uses Castle Windsor in a Windows Service 如何托管在Windows服务中使用Castle Windsor的WCF服务

But if it isn't, then I suggest you try asking on the castle user forum . 但如果不是,那么我建议你尝试询问城堡用户论坛

With Castle 3.0, the way to do this is as follows: 使用Castle 3.0,执行此操作的方法如下:

// setup IoC, including registering the WcfFacility from Castle.WcfIntegrationFacility
container.AddFacility<WcfFacility>();
// and all other registrations you need

And then, assuming you have the necessary details in your app.config or are fine with the defaults: 然后,假设您在app.config有必要的详细信息,或者使用默认值:

// T is an interface with a backing service implementation registered in your IoC
public static ServiceHostBase StartHostService<T>(string serviceUrl)
{
    var assemblyQualifiedName = typeof(T).AssemblyQualifiedName;
    var serviceHost = new DefaultServiceHostFactory()
        .CreateServiceHost(assemblyQualifiedName, new[] { new Uri(serviceUrl) });
    serviceHost.Open();

    return serviceHost;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM