I am having a timeout issue, these are the details:
My binding configuration looks like this:
<netTcpBinding>
<binding name="WindowsServerOverTcp"
maxReceivedMessageSize="10000000"
maxBufferSize="10000000"
maxBufferPoolSize="10000000"
closeTimeout="00:00:03"
openTimeout="00:00:03"
sendTimeout="00:00:03"
receiveTimeout="00:00:03">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
</netTcpBinding>
I am sending a message to a server which I know is turned off so the connection should just time out after 3 seconds as stipulated in my app.config, but for some reason it is taking 20-30 seconds.
When the EndPointNotFoundException is thrown this is the info I get:
System.ServiceModel.EndPointNotFoundException:
Could not connect to
net.tcp://10.0.0.82:4466/MegaMatcherWcf.
The connection attempt lasted for a
time span of 00:00:03. TCP error code
10060: A connection attempt failed
because the connected party did not
properly respond after a period of
time, or established connection failed
because connected host has failed to
respond 10.0.0.82:4466
If I try the same test with the machine turned on, but no listening software running I get the expected behaviour, with the connection timing out after 3 seconds. Why if the machine is off does it take 30 seconds, and then tell me it took 3 seconds?
I believe you are dealing with a Windows timeout issue now, not your WCF timeout. Windows will take 20-30 seconds to determine that a machine is not responding on the network. When you make your call to the WCF server, Windows first has to establish a route to the server. When it can't, it alerts your software and your software thinks that it reached its own timeout. Your system never gets to the point of actually polling to see if the service is running because Windows is still trying to find something at the other end of that IP address.
To be a bit more specific than @BiggsTRC (whose answer is broadly correct):
- WCF delegates to the
System.Net.Sockets
classes the details of
establishing the transport layer connection in
a NetTcpBinding channel;
System.Net.Sockets
is a wrapper around the unmanaged WINSOCK API;
- The WINSOCK API has internal default timeouts but does not provide any documented mechanism for specifying a timeout on certain blocking operations, including
WSAConnect()
, which the .NET Socket.Connect()
method uses;
- The WCF code (in
System.ServiceModel.Channels.SocketConnectionInitiator.Connect()
) calls Socket.Connect
, and if this throws an exception of certain types, it checks to see whether there is any remaining time in its connection timeout period. If there isn't, you get an EndpointNotFoundException
with the error message you have seen;
- WCF uses a
TimeoutHelper
class to keep track of timeout periods and do the time arithmetic. This has a method called ElapsedTime
, but this is a misnomer since it never returns a value greater than the original timeout period: that is the reason the error message lies to you about how long the connection attempt took.
WCF could enforce its configured timeouts by using the asynchronous methods of the Sockets API, monitoring the timeout on a separate thread to the connect attempt, but it does not currently do so. If you think this is a bug (which arguably it is) you could report it on Microsoft's Connect Site and perhaps get it fixed in a future version or service pack.
I was facing the same problem
Did every thing, tried every configuration nothing helped.
net.tcp over internet is timing out like hell on lengthy processes
the only thing that helped me is when i used
Duplex or Callback Message Exchange Pattern
https://msdn.microsoft.com/en-us/library/ff395349.aspx