Thoughts about the WCF channel in CSLA 3.5

Thoughts about the WCF channel in CSLA 3.5

Old forum URL: forums.lhotka.net/forums/t/5538.aspx


Boris posted on Monday, October 06, 2008

I'm using CSLA 3.5.1-080803 with the WCF channel.

Started digging deeper into the CSLA implementation in that area after hitting some strange behaviour while executing a bunch of integration tests...

This post is about the pattern below (WcfProxy class in csla):
   public DataPortalResult Create(Type objectType, object criteria, DataPortalContext context)
    {
      ChannelFactory<IWcfPortal> cf = new ChannelFactory<IWcfPortal>(_endPoint);
      IWcfPortal svr = cf.CreateChannel();
      WcfResponse response =
        svr.Create(new CreateRequest(objectType, criteria, context));
      cf.Close();

      object result = response.Result;
      if (result is Exception)
        throw (Exception)result;
      return (DataPortalResult)result;
    }

Now,
I'm not an expert in WCF, but it looks to me just closing the chanell there might be dangerous...
In many case (usually after an exception) the channel simply won't close...! It needs to be aborted, otherwise it will just hang in there in a weard state...

Here is more info:
http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/
http://msdn.microsoft.com/en-us/library/aa354510.aspx

For our own WCF services we're now using a wrapper, where we have piece of code like:

        private bool ShouldAbort()
        {
            return ((IChannel)this.wcfServiceClient).State !=
                CommunicationState.Closed ||
                ((IChannel)this.wcfServiceClient).State != CommunicationState.Closing;
        }

        private void Dispose(bool isDisposing)
        {
            if (!this.isDisposed)
            {
                if (isDisposing)
                {
                    if (this.wcfServiceClient != null && this.ShouldAbort())
                    {
                        ((IChannel)this.wcfServiceClient).Abort();
                    }
                }
                this.isDisposed = true;
            }
        }






RockfordLhotka replied on Monday, October 06, 2008

Thank you, we'll look into this.

Boris replied on Tuesday, October 07, 2008

I though I'd share this...

Exploring WCF - The Close vs Abort confusion
http://vanryswyckjan.blogspot.com/2007/05/exploring-wcf-close-vs-abort-confusion.html

Copyright (c) Marimer LLC