它看起來像WCF TCP連接不是持久的。第一次ping回覆需要一段時間,但後續進程需要更少的時間。過了一段時間又需要很長時間 - 另一次重新連接?如何製作/模擬持續的TCP連接?
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
如果是這樣,那麼tcp連接的空閒時間值在斷開之前是多少?我需要保持連接活着。
更新修改後的代碼:
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();
現在,我得到另一個錯誤:
The action http://tempuri.org/IService/Pong is not supported by this endpoint. Only WS-ReliableMessaging February 2005 messages are processed by this endpoint.
更新我只修改服務器端和它造成的誤差。然後我將客戶端的TCP作爲可靠的消息傳遞進行修改
真實世界測試:以3秒爲間隔ping應答〜100ms。如果間隔是60秒,那麼回覆是〜500ms,再加上1s520ms(可能重新連接) –
我想我需要啓用該超時:reliableSession> enable = true; inactivityTimeout = 10s; –