WCF: Is it safe to override the Client's Dispose method using a partial class?

Posted by pdiddy on Stack Overflow See other posts from Stack Overflow or by pdiddy
Published on 2010-04-08T22:08:13Z Indexed on 2010/04/08 22:23 UTC
Read the original article Hit count: 334

Filed under:
|
|

I'd like to override the Dispose method of generated proxy (ClientBase) because of the fact that disposing of a proxy calls Close and can throw an exception when the channel is faulted.

The only way I came up was to create a partial class to my generated proxy, make it inherit from IDisposable:

 public partial class MyServiceProxy : IDisposable
    {
        #region IDisposable Members

        public void Dispose()
        {
            if (State != System.ServiceModel.CommunicationState.Faulted)
                Close();
            else
                Abort();
        }

        #endregion
    }

I did some test and my Dispose method is indeed called.

Do you see any issue with this strategy?

Also, I don't like the fact that I'll have to create this partial class for every generated proxy.

It be nice if I was able to make my proxy inherit from a base class...

© Stack Overflow or respective owner

Related posts about wcf

Related posts about .NET