Castle WCF facility Container Configuration
Asked Answered
H

1

0

I'm having real trouble with the WCF Facility provided by Castle Windsor. I'm not finding appropriate documentation which could point me to some examples with the current version of WCF Facility.

Following is my scenario: I want to write a WCF service, exposed over TCP which will be hosted by a Windows Service.

I'm falling short of how to configure the WCF facility, where to configure it whether it should be in the WCF service or in the windows service host.

Also how would I configure the WCF facility when my service end points are declared in the WCF config file?

Can someone please help? A link would be much appreciated, although I could not find much.

Heartwhole answered 29/5, 2012 at 8:11 Comment(0)
K
2

This is an example/walk-through of setting up a (contrived) service.

For my example, there is a service contract WindsorWCF.IMyService and a service called WindsorWCF.MyService. I've chosen to configure the service with a TCP endpoint in the app config as follows:

<system.serviceModel>
  <services>
    <service name="WindsorWCF.MyService">
      <endpoint name ="IMyService_Endpoint" address="net.tcp://localhost:9876/MyService" binding="netTcpBinding" contract="WindsorWCF.IMyService" />
    </service>
  </services>
</system.serviceModel>

Next, add an Window config (XML) file to your service project, and add a component to it:

<configuration>
  <components>
    <component id="MyService" service="WindsorWCF.IMyService, WindsorWCF" type="WindsorWCF.MyService, WindsorWCF" />
  </components>
</configuration>

In the service host application itself, I've added the following code (I used a console application when I wrote the code, but the idea is the same):

static void Main(string[] args)
{
    InitWindsor();
    var host = new DefaultServiceHostFactory().CreateServiceHost("MyService", new Uri[0]);
    host.Open();
    Console.ReadLine();
}

static IWindsorContainer Container { get; set; }
private static void InitWindsor ()
{
    Container = new WindsorContainer().AddFacility<WcfFacility>().Install(Configuration.FromXmlFile("windsor.config"));
}

That's it for the example - I trust it makes sense.

Knockknee answered 29/5, 2012 at 9:26 Comment(2)
Thanks!!! How will I configure the dependencies to my service. I would like to ideally put them inside a Windsor intaller. In your example:How do I set up the dependencies of MyService (lets say its an IRepository) inside the code, rather from the config file?Heartwhole
This is an older thread, but am in similar situation. How can I host multiple services using config file? please advise.Reconcile

© 2022 - 2024 — McMap. All rights reserved.