我有一個Windows服務託管的WCF服務。這使用「發佈預訂」模式將事件發佈到多個訂戶。但是,我發現經過一段時間不活動後,連接失敗,並且我得到可靠的會話是錯誤的錯誤。我試圖通過更改不活動超時並接收timout設置來解決此問題,但它沒有任何區別。說實話,這讓我很生氣。WCF回調計時器
我提到過的一個解決方案是每隔一段時間就「ping」所有用戶。 (例如超時時間的一半)。
設置「ping」的最佳方式是什麼?即如何向服務添加定時器以及如何讓該定時器調用ping功能?
編輯:
我不與平的解決方案完全滿意,並希望進一步調查爲什麼我的可靠的會話保持超時。下面是該服務
服務器的app.config
<binding name="WSDualHttpBinding_IError" receiveTimeout="24.20:31:23.6470000">
<reliableSession inactivityTimeout="24.20:31:23.6470000" />
</binding>
客戶端的app.config
<binding name="WSDualHttpBinding_IError" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="24.20:31:23.6470000"
sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="24.20:31:23.6470000" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
我試過「無限」,而那麼這個值,但它不喜歡它的綁定配置。說,即使谷歌搜索的幾個頁面建議這樣做,該值是無效的。我只能假設這是有效的WCF/.NET的早期版本
EDIT2:
這裏是異常日誌。它絕對確實是一個隨機的時間。
************** Exception Text **************
System.TimeoutException: The operation did not complete within the allotted timeout of 00:00:59.4979498. The time allotted to this operation may have been a portion of a longer timeout.
Server stack trace:
at System.ServiceModel.Channels.InterruptibleWaitObject.Wait(TimeSpan timeout, Boolean throwTimeoutException)
at System.ServiceModel.Channels.ReliableInputConnection.Close(TimeSpan timeout)
at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnClose(TimeSpan timeout)
at System.ServiceModel.Channels.ClientReliableDuplexSessionChannel.OnClose(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnClose(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ClientBase`1.Close()
at MyApp.Form1.buttonError_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
您可以發佈您的配置代碼或配置文件,您可以設置超時?什麼是確切的異常和拋出異常的代碼? – Jan
我已經浪費了太多的時間來解決超時問題。我只想知道如何設置ping的東西。不過謝謝。 – Jonnster
@Jonnster * ping *是錯誤的方式。你會創建一個hacky的解決方案,將你咬在底部。 – oleksii