【发布时间】:2018-08-27 05:49:53
【问题描述】:
我想托管两个服务
- 服务 1(位于 D 驱动器上) 基于 xml 中配置的配置处理数据 net.tcp://ServerIP/Pune_service
- 服务 2(位于 E 驱动器上) 基于 xml 中配置的配置处理数据 net.tcp://ServerIP/Mumbai_service
现在我尝试在两个不同的 Windows 服务中使用 net.tcp 绑定来托管这些服务 Windows 服务 1 启动成功 但是当试图启动第二个 Windows 服务时,我得到了错误,即 AddressAlreadyInUseException
string httpBaseAddress = "http://" + _szServerIP + "/" + _szCurruntLocation + "_FileServer";
string tcpBaseAddress = "net.tcp://" + _szServerIP + "/" + _szCurruntLocation + "_FileServer";
Uri[] adrbase = { new Uri(httpBaseAddress), new Uri(tcpBaseAddress) };
m_svcHost = new ServiceHost(typeof(MyService.CalcServiceClient), adrbase);
ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();
//mBehave.AddressFilterMode=AddressFilterMode.Any)]
m_svcHost.Description.Behaviors.Add(mBehave);
BasicHttpBinding httpb = new BasicHttpBinding();
m_svcHost.AddServiceEndpoint(typeof(MyService.ICalcService), httpb, httpBaseAddress);
m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
NetTcpBinding tcpb = new NetTcpBinding();
tcpb.MaxConnections = 10;
tcpb.MaxReceivedMessageSize = Int32.MaxValue;
tcpb.MaxBufferPoolSize = Int32.MaxValue;
tcpb.MaxBufferSize = Int32.MaxValue;
tcpb.ReceiveTimeout = new TimeSpan(0, 10, 0);
tcpb.OpenTimeout = new TimeSpan(0, 10, 0);
tcpb.CloseTimeout = new TimeSpan(0, 10, 0);
tcpb.PortSharingEnabled = true;
m_svcHost.AddServiceEndpoint(typeof(MyService.ICalcService), tcpb, tcpBaseAddress);
m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
m_svcHost.Open();
Console.WriteLine("Service is live now at : {0}", httpBaseAddress);
Console.ReadLine();
【问题讨论】:
-
我尝试了 Google 的所有解决方案,但没有奏效。我也在发布我的代码请帮助..