title: Calling WCF service using extension method
body: <p>I've written an extension method for use with WCF services that keeps all the disposal and exception handling logic in one place. The method is as follows:</p>
  
  <pre><code>public static TResult CallMethod&lt;TChannel, TResult&gt;(
      this ClientBase&lt;TChannel&gt; proxy,
      Func&lt;TResult&gt; func) where TChannel : class
  {
      proxy.ThrowIfNull("proxy");
      func.ThrowIfNull("func");
  
      try
      {
          // set client credentials
          return func();
      }
      finally
      {
          if (proxy != null)
          {
              try
              {
                  if (proxy.State != CommunicationState.Faulted)
                  {
                      proxy.Close();
                  }
                  else
                  {
                      proxy.Abort();
                  }
              }
              catch (CommunicationException)
              {
                  proxy.Abort();
              }
              catch (TimeoutException)
              {
                  proxy.Abort();
              }
              catch (Exception)
              {
                  proxy.Abort();
                  throw;
              }
          }
      }
  }
  </code></pre>
  
  <p>The method will be used like this:</p>
  
  <pre><code>public int CreateBusinessObject(BusinessObject item)
  {
      MyServiceClient proxy = new MyServiceClient();
      return proxy.CallMethod(() =&gt; proxy.CreateBusinessObject(item));
  }
  </code></pre>
  
  <p>My question really is whether this would be better as a static method which creates the service proxy? I'm slightly worried about my current implementation. Should the construction of the proxy be inside the try/catch? My current understanding is that if the constructor fails, there is nothing to dispose of anyway.</p>