【发布时间】:2020-12-09 14:21:38
【问题描述】:
我有一个单元测试可以在某些计算机上运行而在其他计算机上失败。它确实启动了我们的一个组件,该组件具有自托管的 WCF 服务。
当它尝试启动时,我得到了这个异常:
System.ServiceModel.CommunicationException: 'The service endpoint failed to listen on the URI 'net.tcp://0.0.0.0:55000/VF1/IAccessRightsService' because access was denied. Verify that the current user is granted access in the appropriate allowAccounts section of SMSvcHost.exe.config.'
at System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.ReadEndpoint(String sharedMemoryName, String& listenerEndpoint)
at System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.HandleServiceStart(Boolean isReconnecting)
at System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.Open(Boolean isReconnecting)
at System.ServiceModel.Channels.SharedConnectionListener.StartListen(Boolean isReconnecting)
at System.ServiceModel.Channels.SharedTcpTransportManager.OnOpenInternal(Int32 queueId, Guid token)
at System.ServiceModel.Channels.SharedTcpTransportManager.OnOpen()
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.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
我见过一些类似的问题:WCF error with net.tcp "The service endpoint failed to listen on the URI because access was denied
但就我而言,一切都是在代码中配置的,我找不到任何方法来设置那些“通过代码允许的帐户”。
以下是 TCP 绑定的配置方式:
public ServiceBinding BuildBinding(String instanceName, string serviceName, bool isFastFailing)
{
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
binding.ReliableSession.Enabled = true;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
binding.MaxBufferPoolSize = Int64.MaxValue;
binding.MaxBufferSize = Int32.MaxValue;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.SendTimeout = new TimeSpan(0, 0, isFastFailing ? TIMEOUT_FOR_FAST_FAILING_SERVICE : TIMEOUT_FOR_NORMAL_SERVICE);
binding.ReceiveTimeout = WcfOperationsConstants.INACTIVITY_TIMEOUT;
binding.OpenTimeout = new TimeSpan(0, 0, 2);
binding.CloseTimeout = new TimeSpan(0, 0, 2);
binding.PortSharingEnabled = true;
Uri uri = new Uri(String.Format(URI_FORMAT, m_ip, m_port, instanceName, serviceName));
return new ServiceBinding(uri, binding);
}
(那么,它们只是添加到ServiceHost 的端点。
那么,如何在代码中配置呢?或者您对可能是什么问题有任何其他想法? 为什么它可以在某些计算机上运行?
谢谢
【问题讨论】:
标签: c# .net wcf self-hosting