开发者

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.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜