title: WCF, channel factory, and exceptions
body: <p>Using vs2008, vb.net, C#, fw 3.5</p>
  
  <p>I am consuming my service in my client</p>
  
  <p>Service is hosted in IIS</p>
  
  <p>Client(winforms MDI) is generated using svcutil using /l, /r, /ct, &amp; /n switches</p>
  
  <p>Service and client both use a MyEntities.dll</p>
  
  <p>I am using nettcp with TransportWithMessageCredential
  I cache the proxy in the main form</p>
  
  <pre><code>if  Membership.ValidateUser(UsernameTextBox.Text, PasswordTextBox.Text)
      _proxy = new MyServiceClient
      _proxy.ClientCredentials.UserName.UserName = "username"
      _proxy.ClientCredentials.UserName.Password = "password"
  </code></pre>
  
  <p>I then pass the _proxy around to any child forms/plugins that need to use it
  ex</p>
  
  <pre><code>List(of Orders) =  _proxy.ChannelFactory.CreateChannel.GetOrders(customer)
  </code></pre>
  
  <p>Everything is working great but my questions are this:</p>
  
  <p>What happens to the channels after the call? Are they magically disposed?</p>
  
  <p>How could I monitor this, with a profiler?</p>
  
  <p>Is there a way I can have error handling in one place, or do I need to place try/catch in every call like <a href="https://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue">What is the best workaround for the WCF client `using` block issue?</a></p>
  
  <pre><code>try
  {
      ...
      client.Close();
  }
  catch (CommunicationException e)
  {
      ...
      client.Abort();
  }
  catch (TimeoutException e)
  {
      ...
      client.Abort();
  }
  catch (Exception e)
  {
      ...
      client.Abort();
      throw;
  }
  </code></pre>
  
  <p>Could I subscribe to the  _proxy.InnerChannel.Faulted and do that clean up there?</p>
  
  <p>Regards</p>
  
  <p>_Eric</p>