【发布时间】:2012-06-03 02:09:03
【问题描述】:
我尝试在我的 WCF 项目中使用 Castle WCF 集成工具,但在路上迷路了。你能帮帮我吗?
所以,情况如下:
我有一个 WCF 服务库,它通过 TCP 托管在 Windows 服务中。 以下是我的 WCF 服务库中的内容: 服务实现:
[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 服务还是从 Windows 注册)托管 WCF 服务的服务)。
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 服务的例子。你能帮忙吗?即使是适当的链接也会有所帮助。
谢谢, -迈克
【问题讨论】:
标签: c# wcf c#-4.0 castle-windsor wcffacility