我想在我的WCF项目中使用城堡WCF集成设施,但迷路了。你能帮我解决吗?城堡WCF设施| Windows服务托管
所以,这里的情况是:
我有一个WCF服务库,这是一个Windows服务中通过TCP主持。 下面是什么在我的WCF服务库: 服务默认地将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;
}
}
配置:
<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>
容器配置这是WCF项目被我注册的一切城堡里(我不知道wcf设施应该在哪里注册,应该从WCF服务还是从承载WCF服务的Windows服务注册。
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.
}
}
下面是什么在我的Windows服务:
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;
}
}
而且我对Windows服务配置(app.config)中是一样的我的WCF服务,从字面上看一行行。
现在的问题是,我如何将这一切与WCF设施连接在一起?我已经看到很多使用http和global.asax的例子,但没有一个用于windows服务。你能帮忙吗?即使是适当的链接也是有帮助的。
感谢, -Mike