我有一个由Windows服务托管的WCF服务库。我正在使用Castle Windson进行构造函数注入。当我尝试启动服务时,我得到一个异常,其中包含以下内部异常:
{"A registration already exists for URI 'net.tcp://localhost:8056/LoggingServiceWCF/tcp'."}
App.config中:
<system.serviceModel>
<services>
<service name="LoggingServiceWCF.LoggingService">
<endpoint address="tcp" binding="netTcpBinding" bindingConfiguration="" name="netTcp" contract="LoggingServiceWCF.ILoggingService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="tcpMex" binding="mexTcpBinding" bindingConfiguration="" name="mexTcp" contract="IMetadataExchange" />
<endpoint address="pipe" binding="netNamedPipeBinding" bindingConfiguration="" name="namedPipe" contract="LoggingServiceWCF.ILoggingService" />
<endpoint address="pipeMex" binding="mexNamedPipeBinding" contract="IMetadataExchange" bindingConfiguration="" name="mexPipe" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8056/LoggingServiceWCF" />
<add baseAddress="net.pipe://localhost/LoggingServiceWCF"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Castle windsor安装程序:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<WcfFacility>();
container.Register(Component
.For<LoggerServiceCore.Interfaces.ILogger>()
.ImplementedBy<LogManager>(),
Component
.For<ILoggingService>()
.ImplementedBy<LoggingService>()
.LifeStyle.Transient
.AsWcfService());
container.Register(Component
.For<ServiceBase>()
.ImplementedBy<LoggingHostService>());
}
的Program.cs:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
#if DEBUG
Debugger.Launch();
#endif
ServiceBase.Run(CreateContainer().Resolve<ServiceBase>());
}
private static IWindsorContainer CreateContainer()
{
var container = new WindsorContainer();
container.Install(FromAssembly.This());
return container;
}
}
Windows服务类:
public partial class LoggingHostService : ServiceBase
{
internal static ServiceHost service = null;
public LoggingHostService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if(service != null)
{
service.Close();
}
service = new ServiceHost(typeof(LoggingServiceWCF.LoggingService));
service.Open();
}
protected override void OnStop()
{
if(service != null)
{
service.Close();
service = null;
}
}
}
我已经用Google搜索并找到了解决类似问题的各种解决方案,但我似乎无法找到适用于我案例的方法。