gpt4 book ai didi

c# - WCF:运行几秒钟后出现 EndpointNotFoundException

转载 作者:太空狗 更新时间:2023-10-29 21:59:00 24 4
gpt4 key购买 nike

我正在使用两个应用程序,一个有一个配置为使用 net.tcp 绑定(bind)的自托管服务。服务的 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 默认值:

  • MaxConcurrentSessions:100 * ProcessorCount
  • MaxConcurrentCalls:16 * ProcessorCount
  • MaxConcurrentInstances:默认为以上两者之和,与之前的模式相同。

我使用的是四核机器并且启用了 Net.Tcp 端口共享服务。

客户端应用程序有一个到使用 ChannelFactory 类创建的服务的 channel 。创建 channel 后,将产生 100 个线程。每个线程使用 channel 以每秒一条消息的频率向服务器发送消息。

几秒钟后运行正常(客户端向服务器发送消息并正确接收它们),抛出 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.

奇怪的是:

  • 如果我在同一台机器上运行这两个应用程序,则异常的时间跨度约为 2 秒,但如果我在我的机器上运行服务器应用程序而在不同的机器上运行客户端应用程序,则异常的时间跨度始终为 1第二。
  • 有时(比如十分之一)不会抛出异常,两个应用程序都可以正常工作。
  • 在抛出异常之前,服务器接收消息并正确处理它们。服务器中不会​​抛出任何异常。

我做了很多测试,减少线程数量,增加线程数量,将关闭、打开、接收和发送超时更改为更低和更高的值,为 maxConnections 设置更高的值,但结果始终相同,在有些时候会抛出 EndpointNotFoundException。我即将放弃并更改代码,以便每个线程都有自己的 channel ,希望这能解决问题,但我想知道为什么会这样。如果有人知道我做错了什么或者可以指出正确的方向继续调查,那将会很有帮助。

最佳答案

默认情况下,Windows 不启用端口共享。我会检查您是否已正确启用它(see here)。

如果可能,您还可以尝试更改一个应用程序的端口,或者在 VM 中测试一个应用程序。

此外,对于可能遇到相同问题的任何其他人,请按照 Diego 所做的操作并检查配置中是否启用了端口共享。将 portSharingEnabled="true" 添加到绑定(bind)中:

<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>

取自:http://msdn.microsoft.com/en-us/library/ms731810.aspx

关于c# - WCF:运行几秒钟后出现 EndpointNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10125973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com