title: ChannelFactory: creating and disposing
body: <p>I have written an Sdk that is used by a WPF client, and takes care of calling WCF services and caching. These WCF services are called using the ChannelFactory, so I don't have service references. To do that, I created a factory that handles opening and closing ChannelFactory and ClientChannel as follows:</p>
  
  <pre><code>public class ProjectStudioServiceFactory : IDisposable
  {
      private IProjectStudioService _projectStudioService;
      private static ChannelFactory&lt;IProjectStudioService&gt; _channelFactory;
  
      public IProjectStudioService Instance
      {
          get
          {
              if (_channelFactory==null) _channelFactory = new ChannelFactory&lt;IProjectStudioService&gt;("ProjectStudioServiceEndPoint");
              _projectStudioService = _channelFactory.CreateChannel();
              ((IClientChannel)_projectStudioService).Open();                
              return _projectStudioService;
          }
      }
  
      public void Dispose()
      {
          ((IClientChannel)_projectStudioService).Close();
          _channelFactory.Close();
      }       
  }
  </code></pre>
  
  <p>And each request I call like:</p>
  
  <pre><code> using (var projectStudioService = new ProjectStudioServiceFactory())
          {
              return projectStudioService.Instance.FindAllCities(new FindAllCitiesRequest()).Cities;
          }
  </code></pre>
  
  <p>Although this works, it's slow because for every request the client channel and factory is opened and closed. If I keep it open, it's very fast. But I was wondering what the best practise would be? Should I keep it open? Or not? How to handle this in a correct way?</p>