开发者

WCF Integration Facility and Self-Hosted Services

开发者 https://www.devze.com 2022-12-24 05:33 出处:网络
I\'m self-hosting several开发者_运维知识库 services where I do this to register the service: host = new ServiceHost(typeof(MyService));

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.

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?

The example seems shows IIS hosted services where the 1st line of the MyService.svc file looks like:

<%@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.


This may be helpful:
How to host a WCF service that uses Castle Windsor in a Windows Service

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:

// 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:

// 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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消