首页 > 解决方案 > 即使在中止后重新注册 WCF 端点也“已经存在”

问题描述

我在使用 Azure 服务结构的 WCF 端点管理器高可用性 Windows 服务方面遇到了一个奇怪的问题,该服务在服务变为活动状态时提供回调。

每次服务激活时,我们使用以下方法注册 WCF 端点:

一个)

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

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

二)

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 应该释放资源,这样当我们继续并再次注册此端点时,它应该可以正常工作。

我在这里错过了什么吗?

标签: c#wcfexception-handlingfault

解决方案


推荐阅读