Castle WCF Facility | Windows Service Hosting

887 views
Skip to first unread message

Mijo Thomas

unread,
May 28, 2012, 5:33:29 PM5/28/12
to Castle Project Users
I’m trying to use Castle WCF integration facility in my WCF project,
but got lost in the way. Can you please help me out?

So, here is the situation:

I have a WCF Service Library, which is hosted inside a Windows Service
over TCP. Following is what is in my WCF Service Library: Service
Impl:

[ServiceContract]
public interface ICalculatorService
{
[OperationContract]
int Add(int x, int y);
}

public class CalculatorService : ICalculatorService
{
public int Add(int x, int y)
{
return x + y;
}
}
Configuration:

<system.serviceModel>
<services>
<service name="namespace.CalculatorService">
<endpoint address="" binding="netTcpBinding"
bindingConfiguration=""
contract="namespace.iCalculatorService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding"
bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/
CalculatorService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

Container Configuration This is inside WCF project were I register
everything to castle (I'm not sure where the wcf facility should be
registered, whether it should be registered from the WCF service or
from the Windows service which hosts the WCF service).

public class ConfigureContainerCastle
{
private readonly IWindsorContainer container;

public ConfigureContainerCastle(IWindsorContainer container)
{
this.container = container;
}

public void Configure()
{
// Any component registration.

container.Register(Component.For<ICalculatorService>().ImplementedBy<CalculatorService>());
//All other component registration.
}
}
Following is what is in my Windows Service:

public class Host<T>:ServiceBase
{
private ServiceHost serviceHost = null;
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}

// How do I call the DefaultServiceHostFactory and
start the service?
// Should I call the WCF facility from here or from
WCF service library?
// var container = new WindsorContainer();
// var configureContainer = new
DataServicesConfigureContainer(container);
// var hostFactory = new
DefaultServiceHostFactory(container.Kernel);

serviceHost = new ServiceHost(typeof (T));
serviceHost.Open();
}

protected override void OnStop()
{
if (serviceHost == null)
return;

serviceHost.Close();
serviceHost = null;
}
}
And my configuration(app.config) for Windows Service is same as my WCF
service, literally line by line.

Now the question is, how do I wire this all together with WCF
facility? I have seen lot of examples using http and global.asax, but
none for windows services. Can you please help? Even an appropriate
link to it will be helpful.

Thanks, -Mike

Berke Sokhan

unread,
May 29, 2012, 4:36:38 AM5/29/12
to castle-pro...@googlegroups.com
Hello,

Basically, you need zero configuration in app.config file. 

You can do all WCF-specific configuration with fluent registration API presented by WCF facility library extension methods to Castle Windsor container. For samples you can check the unit tests of the project - which are now integrated with Castle.Windsor repo - instead of outdated blog posts spreaded all over...




Also [SetUp] part could ring some bells:



2012/5/29 Mijo Thomas <thoma...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.




--
Berke SOKHAN.

http://twitter.com/berkesokhan
http://blog.berkesokhan.com
http://www.birliktegelistir.com/editors.aspx

Serdar B.

unread,
May 29, 2012, 4:45:19 AM5/29/12
to castle-pro...@googlegroups.com
Hi,

I think this sample is a good basic example for wcf facility with windows service...

(you need to add the installer class)



Serdar
--
serdarb.com
Reply all
Reply to author
Forward
0 new messages