我想在我的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