title: WCF connection reset: server reboot needed
body: <p>This issue is related to a WCF hosted in a windows service on a windows server 2003.</p>
  
  <p><strong>The issue happens after several days of correct working and get fixed only by rebooting the server.</strong></p>
  
  <p>The C# code doesn't catch any exception in its log</p>
  
  <pre><code>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&lt;UnknownMessageReceivedEventArgs&gt;(serviceHost_UnknownMessageReceived);
  
  serviceHost.Open();
  </code></pre>
  
  <p>The handlers are implemented like that:</p>
  
  <pre><code> 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);
          }   
      }
  }
  </code></pre>
  
  <p>On client side, C# WCF consumer correctly closes the connection, after invoking an operation.</p>
  
  <p>Maximum level tracing has been activated.</p>
  
  <pre><code>   &lt;system.diagnostics&gt;
        &lt;sources&gt;
              &lt;source name="System.ServiceModel" 
                          switchValue="All"
                          propagateActivity="true"&gt;
                  &lt;listeners&gt;
                          &lt;add name="xml" /&gt;
                  &lt;/listeners&gt;
               &lt;/source&gt;
              &lt;source name="CardSpace"
                          switchValue="All"&gt;
                  &lt;listeners&gt;
                      &lt;add name="xml" /&gt;
                  &lt;/listeners&gt;
              &lt;/source&gt;
              &lt;source name="System.IO.Log"
                          switchValue="All"&gt;
                  &lt;listeners&gt;
                      &lt;add name="xml" /&gt;
                  &lt;/listeners&gt;
              &lt;/source&gt;
              &lt;source name="System.Runtime.Serialization"
                          switchValue="All"&gt;
                  &lt;listeners&gt;
                      &lt;add name="xml" /&gt;
                  &lt;/listeners&gt;
              &lt;/source&gt;
              &lt;source name="System.IdentityModel"
                          switchValue="All"&gt;
                  &lt;listeners&gt;
                      &lt;add name="xml" /&gt;
                  &lt;/listeners&gt;
              &lt;/source&gt;
              &lt;source name="System.ServiceModel.MessageLogging"
                          switchValue="All"&gt;
                  &lt;listeners&gt;
                      &lt;add name="xml" /&gt;
                  &lt;/listeners&gt;
              &lt;/source&gt;
              &lt;source name="System.ServiceModel.Activation"
                          switchValue="All"&gt;
                  &lt;listeners&gt;
                      &lt;add name="xml" /&gt;
                  &lt;/listeners&gt;
              &lt;/source&gt;
        &lt;/sources&gt;
  
          &lt;sharedListeners&gt;
              &lt;add name="xml"
                   type="System.Diagnostics.XmlWriterTraceListener"
                   initializeData="C:\MyPath\Traces.svclog" /&gt;
          &lt;/sharedListeners&gt;
  &lt;trace autoflush="true" /&gt;
     &lt;/system.diagnostics&gt; 
  </code></pre>
  
  <p>with </p>
  
  <pre><code>    &lt;system.serviceModel&gt;
    &lt;diagnostics wmiProviderEnabled="true"&gt;
        &lt;messageLogging 
             logEntireMessage="true" 
             logMalformedMessages="true"
             logMessagesAtServiceLevel="true" 
             logMessagesAtTransportLevel="true"
             maxMessagesToLog="3000" 
         /&gt;
    &lt;/diagnostics&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    &lt;serviceBehaviors&gt;
          &lt;behavior name="MyServiceBehavior"&gt;
              &lt;dataContractSerializer maxItemsInObjectGraph="6553500"/&gt;
              &lt;serviceMetadata httpGetEnabled="true"/&gt;
              &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
      &lt;/serviceBehaviors&gt;
  </code></pre>
  
  <p>Operating system checks seem fine</p>
  
  <pre><code>netstat -ao | grep 9nnn
  tasklist /SVC | grep Opxxx
  </code></pre>
  
  <p>My feeling was that the channel listeners are not working, but nothing shows any issues in the trace log.
  The server just stops responding to requests for this WCF, but it writes nothing to logs from that moment on.
  From a visual perspective here it is the non-responding versus the ok graph.</p>
  
  <p><a href="https://i.stack.imgur.com/fox0O.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fox0O.png" alt="non-responding"></a> - vs - <a href="https://i.stack.imgur.com/tqMRo.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tqMRo.png" alt="enter image description here"></a></p>
  
  <p>Could someone suggest a softer solution than rebooting the server? Obviously, already tried to restart the host service (and other system services like dns and ipsec) and even reinstalled the WCF. Only rebooting the server does the trick.</p>
  
  <p>Any idea what could be the root cause?</p>
  
  <p><strong>Edit - after the reboot</strong></p>
  
  <p>After the reboot - <em>without any other changes</em> - the WCF started to work again.</p>
  
  <p><strong>Side note</strong></p>
  
  <p>There is another minor point that I don't fully understand.
  Running now - when everything is working fine - the command</p>
  
  <pre><code>httpcfg.exe query urlacl 
  </code></pre>
  
  <p>that is the windows 2003 version of</p>
  
  <pre><code>netsh http show urlacl
  </code></pre>
  
  <p>I would have expected to see the WCF url but the output is only (why?)</p>
  
  <pre><code>C:\&gt;httpcfg.exe query urlacl
      URL : http://+:80/Temporary_Listen_Addresses/
      ACL : D:(A;;GX;;;WD)
  -------------------------------------------------------
  </code></pre>