c# - 即使在中止后重新注册 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 应该释放资源,这样当我们继续并再次注册此端点时,它应该可以正常工作。
我在这里错过了什么吗?
解决方案
推荐阅读
- python - 如何在服务器中执行迭代命令而不使用python登录服务器
- metpy - 如何理解 netCDF 文件的格式
- swift - 收听添加到 Firestore 集合中的任何新文档
- architecture - 具有 Hystrix 和数十种服务的架构
- sql - 尝试在 Ubuntu 上读取格式文件时出现 SQL BCP 未知错误
- python-3.x - 如何在 sql IN 语句中包含不同数量的变量?
- conditional-statements - 使用贝叶斯公式
- c++ - 使用元组在 C++ 中进行 4d 映射
- javascript - 如何解析 JSON 响应并将值存储在数组中
- java - 如何检测我点击了 Windows 任务栏上的应用程序的显示?