即使在中止之后,WCF端点的重新注册也“已经存在”

时间:2018-05-15 17:33:26

标签: c# wcf exception-handling fault

我在使用Azure Service Fabric时遇到WCF端点管理器高可用性Windows服务的奇怪问题,该服务在服务变为活动时提供回调。

每次服务变为活动状态时,我们都会使用以下命令注册WCF端点:

A)

serviceHost = CreateServiceHost(IWcfContractInstance)
serviceHost.AddServiceEndpoint(...)
serviceHost.Open()

每当服务被停用时(注意:在这种情况下进程不会停止)

B)

serviceHost.Close()

它们都处于锁定状态,这里没有同步问题。问题是A失败,说端点已经注册。 堆栈跟踪:

System.InvalidOperationException: The ChannelDispatcher at 'net.tcp://localhost:[PORT]/IWcfContract '"ContractName"' is unable to open its IChannelListener. ---> System.InvalidOperationException: 
A registration already exists for URI 'net.tcp://localhost:[PORT]/IWcfContract'.
at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri; HostNameComparisonMode hostNameComparisonMode; TItem item)
at System.ServiceModel.Channels.ConnectionOrientedTransportManager`1.Register(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ReliableChannelListenerBase`1.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

奇怪的是B)也失败并抛出CommunicationObjectFaultedException。所以问题是,在故障会话中调用Close应该处理resoureces,这样当我们继续并再次注册这个端点时,它应该正常工作。

我在这里错过了什么吗?

0 个答案:

没有答案