title: How to write a WCF service with in-memory persistent storage?
body: <p>I wrote a WCF service, but the data stored in the Service implementation doesn't persists between calls, not even if stored in a static variable. What can I do?</p>
  
  <p>The service implementation is as follows:</p>
  
  <pre><code>public class Storage : IStorage
  {
      protected static object[] _data;
  
      #region IStorage Members
  
      public void Insert(object[] data)
      {
          lock (_data)
          {
               _data = _data.Concat(data).ToArray();
          }
      }
  
      public object[] SelectAll()
      {
          lock (_data)
          {
              return (object[])_data.Clone();
          }
      }
  
      #endregion
  }
  </code></pre>
  
  <p>The service host is a console application:</p>
  
  <pre><code>static void Main(string[] args)
  {
      ServiceHost serviceHost =
         new ServiceHost(typeof(TimeSpanStorage));
      serviceHost.Open();
      Console.WriteLine("Service running.  Please 'Enter' to exit...");
      Console.ReadLine();
  }
  </code></pre>