It looks like WCF TCP connections are not persistent. First ping reply takes a while but subsequent processes take less time. After a while it takes long again -another re-connection?
SERVER> Started on net.tcp://0.0.0.0:999
CLIENT> Connection created to net.tcp://localhost:999 //Not a real connection, ready to connect
CLIENT> Ping reply in 1s163ms //First connection
CLIENT> Ping reply in 22ms //Already connected
CLIENT> Ping reply in 26ms
CLIENT> Ping reply in 24ms
CLIENT> Ping reply in 325ms //Re-connected
CLIENT> Ping reply in 19ms
CLIENT> Ping reply in 767ms //Re-connected
If it's true, what is the idle time value for a tcp connection before it will be disconnected? I need to keep the connection alive.
Update Modified code:
NetTcpBinding tcpBind = new NetTcpBinding();
tcpBind.ReliableSession.Enabled = true;
tcpBind.ReliableSession.Ordered = true;
tcpBind.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10);
ServiceHost svh = new ServiceHost(typeof(ServiceImplementation));
svh.AddServiceEndpoint(
typeof(WCFSimple.Contract.IService),
//new NetTcpBinding(),
tcpBind,
String.Format("net.tcp://{0}:{1}", ip, port));
svh.Open();
Now I got another error:
The action http://tempuri.org/IService/Pong is not supported by this endpoint. Only WS-ReliableMessaging February 2005 messages are processed by this endpoint.
Update I modified only server side and it caused the error. Then I modified client side's TCP as reliable messaging.
No data is sent over the network to maintain TCP connections. You can send a network layer keep-alive simply by send()ing a zero byte packet from either peer or enable socket options to have the operating system periodically send them for you.
Persistent connections provide a mechanism by which a client and a server can signal the close of a TCP connection. This signaling takes place using the Connection header field (section 14.10). Once a close has been signaled, the client MUST NOT send any more requests on that connection.
To maintain a persistent connection, TCP keep-alive packets are sent to prevent the connection from timing out. An open connection is faster for frequent data exchanges. Communications overhead is saved by leaving a connection open rather than opening and closing sessions for each request.
Click Action > Configure Agents > Configure Persistent Connection. Note: The agent must be one for which Agent Manager appears in the Event Manager column. Do one of the following in the Configure Persistent Connection window: To enable the connection, select Enable Persistent Connections for selected agents.
I don't think Ping is a good tool to test a TCP connection. Because Ping uses ICMP as its underlying protocol instead of TCP.
I suggest you create a WCF client, connect to the service and then check the TCP connection via some network sniffering tools or simply use netstat for quick check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With