[英]WCF EndpointNotFoundException when running as NetworkService
[英]WCF: EndpointNotFoundException after running for a couple of seconds
我正在使用两个应用程序,一个具有配置为使用net.tcp绑定的自托管服务。 该服务的ServiceBehaviorAttribute配置为:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,
InstanceContextMode = InstanceContextMode.Single,
IncludeExceptionDetailInFaults = true,
UseSynchronizationContext = false,
ValidateMustUnderstand = false)]
对于服务和客户端,transferMode设置为Streamed,超时为:
closeTimeout="00:01:00"
openTimeout="00:00:30"
receiveTimeout="00:02:30"
sendTimeout="00:02:30"
MaxConnections设置为500,ServiceThrottlingBehavior使用WCF 4默认值:
我使用的是四核机器,并启用了Net.Tcp端口共享服务。
客户端应用程序具有使用ChannelFactory类创建的服务的单个通道。 创建通道后,会生成100个线程。 每个线程使用该通道以每秒一条消息的频率向服务器发送消息。
运行ok几秒钟后(客户端向服务器发送消息并正确接收它们)会抛出EndpointNotFoundException,并显示以下消息:
Could not connect to net.tcp://localhost/service. The connection attempt lasted
for a time span of 00:00:02.1777100. TCP error code 10061: No connection could
be made because the target machine actively refused it 127.0.0.1:808.
奇怪的事情是:
我做了很多测试,减少线程数量,增加线程数量,更改关闭,打开,接收和发送超时值到更低和更高的值,为maxConnections设置更高的值,但结果总是相同的,在某些时候抛出EndpointNotFoundException。 我即将放弃并更改代码,以便每个线程都有自己的通道,希望这可以解决问题,但我想知道为什么会发生这种情况。 如果有人知道我做错了什么或者能指出我正确的方向继续调查它会有所帮助。
默认情况下,Windows不启用端口共享。 我会检查你是否正确启用它( 见这里 )。
如果可能,您还可以尝试更改一个应用程序的端口,或者在VM中测试一个应用程序。
此外,对于可能具有相同问题的任何其他人,请执行Diego已完成并检查配置中是否启用了端口共享。 将portSharingEnabled="true"
添加到绑定:
<system.serviceModel>
<bindings>
<netTcpBinding name="portSharingBinding"
portSharingEnabled="true" />
<services>
<service name="MyService">
<endpoint address="net.tcp://localhost/MyService"
binding="netTcpBinding"
contract="IMyService"
bindingConfiguration="portSharingBinding" />
</service>
</services>
</system.serviceModel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.