WCF: EndpointNotFoundException after starting for a few seconds

I work with two applications, I have a self-service service configured to use the net.tcp binding. Service ServiceBehaviorAttribute is configured using:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true, UseSynchronizationContext = false, ValidateMustUnderstand = false)] 

For both services and the client, the transferMode parameter is set to Streamed, and timeouts are:

 closeTimeout="00:01:00" openTimeout="00:00:30" receiveTimeout="00:02:30" sendTimeout="00:02:30" 

MaxConnections is set to 500, and ServiceThrottlingBehavior uses the default values ​​for WCF 4:

  • MaxConcurrentSessions: 100 * ProcessorCount
  • MaxConcurrentCalls: 16 * ProcessorCount
  • MaxConcurrentInstances: The default value is the sum of the two above, which follows the same pattern as before.

I am using a quad-core machine and the Net.Tcp port exchange service is enabled.

The client application has one channel for a service created using the ChannelFactory class. After creating the channel, 100 threads are generated. Each thread uses a channel to send messages to the server at a frequency of one message per second.

After several seconds of operation (the client sends messages to the server and receives them correctly), an EndpointNotFoundException is thrown with the following message:

 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. 

Weird things:

  • If I run both applications on one computer, the exception time interval is about 2 seconds, but if I run the server application on my computer and the client application on another machine, the exception time interval is always 1 second.
  • Several times (for example, every tenth), an exception is not thrown, and both applications work fine.
  • Before an exception is thrown, the server receives messages and processes them correctly. Exceptions are not thrown on the server.

I have done many tests, reducing the number of threads, increasing them, changing the timeouts for closing, opening, receiving and sending to lower and higher values, setting a higher value for maxConnections, but the result is always the same, at some point an EndpointNotFoundException is thrown. I am going to drop and modify the code so that each thread has its own channel, hoping this fixes the problem, but I want to know why this is happening. If someone knows what I'm doing wrong, or can point me in the right direction to continue the investigation, this will be helpful.

+6
source share
1 answer

By default, Windows does not allow port sharing. I would check that you turned it on correctly ( see here ).

If possible, you can also try changing the port of one application or testing one in the VM.

Also, for anyone who might have the same problem, do as Diego did, and check if ports are allowed in the configuration. Add portSharingEnabled="true" to the binding:

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

Taken from: http://msdn.microsoft.com/en-us/library/ms731810.aspx

+1
source

Source: https://habr.com/ru/post/913045/


All Articles