<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Don&#8217;t Wrap Wcf Service Hosts or Clients in a Using Statement</title>
	<atom:link href="http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/</link>
	<description>Developer.Speaker.Blogger</description>
	<lastBuildDate>Sun, 14 Aug 2011 06:09:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/comment-page-1/#comment-3048</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 01 May 2009 21:33:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/#comment-3048</guid>
		<description>Thanks, I ended up wrapping the channel on client side like so;

&lt;code&gt;
public class ServiceWrapper : IDisposable
    {
        public ServiceWrapper()
        {
            _channelFactory = new ChannelFactory(typeof(T).FullName);
            Channel = _channelFactory.CreateChannel();
        }

        private ChannelFactory _channelFactory;
        public T Channel { get; private set; }

        #region IDisposable Members

        public void Dispose()
        {
            if (_channelFactory != null)
            {
                try
                {
                    ((IDisposable)_channelFactory).Dispose();
                }
                catch (CommunicationException)
                {
                    _channelFactory.Abort();
                }
                catch (TimeoutException)
                {
                    _channelFactory.Abort();
                }
                catch (Exception)
                {
                    _channelFactory.Abort();
                    throw;
                }
            }

        }

        #endregion
    }
&lt;/code&gt;

usage
&lt;code&gt;
using (var wrapper = new ServiceWrapper())
{
    wrapper.Channel.DoSomething();
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Thanks, I ended up wrapping the channel on client side like so;</p>
<p><code><br />
public class ServiceWrapper : IDisposable<br />
    {<br />
        public ServiceWrapper()<br />
        {<br />
            _channelFactory = new ChannelFactory(typeof(T).FullName);<br />
            Channel = _channelFactory.CreateChannel();<br />
        }</p>
<p>        private ChannelFactory _channelFactory;<br />
        public T Channel { get; private set; }</p>
<p>        #region IDisposable Members</p>
<p>        public void Dispose()<br />
        {<br />
            if (_channelFactory != null)<br />
            {<br />
                try<br />
                {<br />
                    ((IDisposable)_channelFactory).Dispose();<br />
                }<br />
                catch (CommunicationException)<br />
                {<br />
                    _channelFactory.Abort();<br />
                }<br />
                catch (TimeoutException)<br />
                {<br />
                    _channelFactory.Abort();<br />
                }<br />
                catch (Exception)<br />
                {<br />
                    _channelFactory.Abort();<br />
                    throw;<br />
                }<br />
            }</p>
<p>        }</p>
<p>        #endregion<br />
    }<br />
</code></p>
<p>usage<br />
<code><br />
using (var wrapper = new ServiceWrapper())<br />
{<br />
    wrapper.Channel.DoSomething();<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WCF &#38; Using Statements - Shawn Weisfeld [MVP]</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/comment-page-1/#comment-1468</link>
		<dc:creator>WCF &#38; Using Statements - Shawn Weisfeld [MVP]</dc:creator>
		<pubDate>Thu, 13 Nov 2008 11:08:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/#comment-1468</guid>
		<description>[...] check out a post by Dan Rigsby that goes into more detail. http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using...  Published Thursday, November 13, 2008 6:29 AM by sweisfeld Filed under: C#, .NET, SOA, VB.NET, [...]</description>
		<content:encoded><![CDATA[<p>[...] check out a post by Dan Rigsby that goes into more detail. <a href="http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using.." rel="nofollow">http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using..</a>.  Published Thursday, November 13, 2008 6:29 AM by sweisfeld Filed under: C#, .NET, SOA, VB.NET, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sidar Ok</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/comment-page-1/#comment-502</link>
		<dc:creator>Sidar Ok</dc:creator>
		<pubDate>Sun, 04 May 2008 13:59:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/#comment-502</guid>
		<description>Thanks for the great read, the issue here is obviously something wrong with the implementation of IDisposable pattern that we always expect for the unmanaged resource to close or dispose safely - appearantly this is not the case with WCF. Another way of solution could have been writing your own ClientBase and handling communication fault exception, do what you need when that exception has arisen, and safely continue to use of &quot;using&quot; or &quot;close&quot; your objects off. what do you think ?

Thanks again. 

Sidar</description>
		<content:encoded><![CDATA[<p>Thanks for the great read, the issue here is obviously something wrong with the implementation of IDisposable pattern that we always expect for the unmanaged resource to close or dispose safely &#8211; appearantly this is not the case with WCF. Another way of solution could have been writing your own ClientBase and handling communication fault exception, do what you need when that exception has arisen, and safely continue to use of &#8220;using&#8221; or &#8220;close&#8221; your objects off. what do you think ?</p>
<p>Thanks again. </p>
<p>Sidar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mehmet</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/comment-page-1/#comment-223</link>
		<dc:creator>Mehmet</dc:creator>
		<pubDate>Wed, 27 Feb 2008 18:19:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/#comment-223</guid>
		<description>Here is a newsgroup discussion that gives some insight on the design decisions regarding Dispose()

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=855018&amp;SiteID=1</description>
		<content:encoded><![CDATA[<p>Here is a newsgroup discussion that gives some insight on the design decisions regarding Dispose()</p>
<p><a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=855018&amp;SiteID=1" rel="nofollow">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=855018&amp;SiteID=1</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

