簡體   English   中英

WCF連接重置:需要重新啟動服務器

[英]WCF connection reset: server reboot needed

此問題與Windows Server 2003上的Windows服務中托管的WCF有關。

問題發生在正確工作幾天后,只能通過重新啟動服務器來解決。

C#代碼在其日志中沒有捕獲任何異常

serviceHost.Opening += new EventHandler(serviceHost_Opening);
serviceHost.Opened += new EventHandler(serviceHost_Opened);
serviceHost.Closing += new EventHandler(serviceHost_Closing);
serviceHost.Closed += new EventHandler(serviceHost_Closed);
serviceHost.Faulted += new EventHandler(serviceHost_Faulted);
serviceHost.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(serviceHost_UnknownMessageReceived);

serviceHost.Open();

處理程序的實現方式如下:

 void serviceHost_Opened(object sender, EventArgs e)
{ 
    CentralReport.MyService.SrvLog("WinCentralRpt",String.Format("service opened by sender: {0}", sender.GetType().ToString()));
}

void serviceHost_Opening(object sender, EventArgs e)
{
    CentralReport.MyService.SrvLog("WinCentralRpt",String.Format("service opening by sender: {0}", sender.GetType().ToString()));
}    

public static void SrvLog(string user, string line) {
    string log_path = System.Configuration.ConfigurationManager.AppSettings["srv_log"];
    if (log_path != null) {
        using (System.IO.StreamWriter logSW = new System.IO.StreamWriter(
            log_path.Replace("{user}",user.ToLower()),true)) {
            logSW.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt", CultureInfo.InvariantCulture) + ": " + line);
        }   
    }
}

在客戶端,C#WCF使用者在調用操作后正確關閉連接。

已激活最大級別跟蹤。

   <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                        switchValue="All"
                        propagateActivity="true">
                <listeners>
                        <add name="xml" />
                </listeners>
             </source>
            <source name="CardSpace"
                        switchValue="All">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.IO.Log"
                        switchValue="All">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.Runtime.Serialization"
                        switchValue="All">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.IdentityModel"
                        switchValue="All">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.ServiceModel.MessageLogging"
                        switchValue="All">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.ServiceModel.Activation"
                        switchValue="All">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
      </sources>

        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="C:\MyPath\Traces.svclog" />
        </sharedListeners>
<trace autoflush="true" />
   </system.diagnostics> 

    <system.serviceModel>
  <diagnostics wmiProviderEnabled="true">
      <messageLogging 
           logEntireMessage="true" 
           logMalformedMessages="true"
           logMessagesAtServiceLevel="true" 
           logMessagesAtTransportLevel="true"
           maxMessagesToLog="3000" 
       />
  </diagnostics>

    <serviceBehaviors>
        <behavior name="MyServiceBehavior">
            <dataContractSerializer maxItemsInObjectGraph="6553500"/>
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>

操作系統檢查似乎沒問題

netstat -ao | grep 9nnn
tasklist /SVC | grep Opxxx

我的感覺是頻道監聽器不工作,但跟蹤日志中沒有任何問題。 服務器只是停止響應此WCF的請求,但它從那一刻開始就不向日志寫入任何內容。 從視覺角度來看,它是無響應的與OK的圖形。

非響應 - vs - 在此輸入圖像描述

有人建議比重啟服務器更軟的解決方案嗎? 顯然,已經嘗試重啟主機服務(以及其他系統服務,如dns和ipsec),甚至重新安裝了WCF。 只有重啟服務器才能解決問題。

知道什么可能是根本原因?

編輯 - 重啟后

重啟后 - 沒有任何其他更改 - WCF再次開始工作。

邊注

還有一點我不完全理解。 現在運行 - 當一切正常 - 命令

httpcfg.exe query urlacl 

那是Windows 2003的版本

netsh http show urlacl

我本來希望看到WCF網址,但輸出只是(為什么?)

C:\>httpcfg.exe query urlacl
    URL : http://+:80/Temporary_Listen_Addresses/
    ACL : D:(A;;GX;;;WD)
-------------------------------------------------------

這是舊版.Net 4.0版本的WCF的ThreadPool中的一個錯誤。 你可以在這里這里找到一些參考。

您應該將服務帳戶從本地系統移動到本地服務。 這是用於保留本地服務帳戶的URL的Windows 2003命令。

httpcfg set urlacl /u http://+:9nnn/Your/Url/ /a "D:(A;;GX;;;LS)"

此外,您只需啟用WCF性能計數器並關閉WCF跟蹤。

<system.serviceModel>
  <diagnostics performanceCounters="All" />
  ...

它們將顯示在性能監視器的Service.ModelService類別下。

總之,使用單獨的進程或使用不同的(非WCF)工作服務替換WCF服務中的線程操作(如數據庫訪問等)。

相關問題

全世界都記錄了類似的問題

技術公告 :在高負載運行后,WCF服務可能無響應

如果症狀適用,請重新啟動托管無響應服務的服務器。

一個有趣的msdn建議可能適合這里

故障排除: 強制關閉連接

原因:

有故障的網絡硬件正在丟棄部分TCP流量

要么

SynAttackProtect設置可能正在丟棄連接。

查看以下注冊表可能會有用

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

以下文章提到了兩個原因:

  • 操作系統內存不足用於TCP緩沖區
  • 操作系統耗盡了可用的TCP“短暫”端口( KB微軟指的是上述注冊表tcp / ip參數

根本問題

它是非分頁池資源問題。

無響應的WCF只是一個早鳥信息,在此之前發送。

實際上,以下是內存泄漏的典型症狀

你仍然可以ping服務器,它仍然處理一些基本命令,如關機命令,但它不允許瀏覽文件或文件夾,你不能RDP到服務器。

你有幾個工具來監控它:

  • 過程探索者
  • Poolmon的

閱讀PearmanRussinovich的這兩篇文章以獲得完整的指導。

旁注

您還可以檢查\\System32\\LogFiles\\HTTPERR下的http日志。

可能會應用修補程序

我以前在使用Web服務的舊版Windows上使用MemoryStream和Binary Writers時遇到了奇怪的問題。 沒有什么比這更有意義了,不知道它是硬件限制還是一些奇怪的一次性.Net錯誤。 也許嘗試將Stream拉出使用塊並使用Try-Finally情況處理它。 在過去與二進制編寫器的問題,我將不得不自己處理它,它工作正常。 幾乎像“使用”塊試圖在它完成之前關閉所有東西。

您是否正在使用服務中的服務? 請記住在消耗服務的任何地方關閉連接(即使在服務器端)。

在WCF中,您可能知道存在ChannelFactory ,該工廠為您提供服務代理,但它也是ICommunicationObject ,您必須配置該服務代理實例以關閉連接。

使用指令PerRequest檢查ServiceHost銷毀,以監視是否允許處理服務主機實例,以及是否存在代碼的其他部分中存在的硬引用,而不允許使用Gcollected。

我認為你可能已經計算出最大連接數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM