65.9K
CodeProject is changing. Read more.
Home

Do not use "using" for WCF Clients

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.88/5 (5 votes)

May 18, 2011

CPOL
viewsIcon

7380

Good Tip, got my 5!As an alternative to your tip, when using generated proxies you could also add the logic to a partial class with the same name as the proxy class, see below.public partial class MyGeneratedProxyClient : IDisposable{ void IDisposable Dispose() { try...

Good Tip, got my 5! As an alternative to your tip, when using generated proxies you could also add the logic to a partial class with the same name as the proxy class, see below.
public partial class MyGeneratedProxyClient : IDisposable
{
   void IDisposable Dispose()
   {
      try
      {
         if (this.State == CommunicationState.Faulted)
           this.Abort();
         else
           this.Close();
       }
       catch
       {
         this.Abort();
       }
   }
}