Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, you do, but you need to be very careful when doing so. While closing anything that implements <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.icommunicationobject.aspx" rel="nofollow noreferrer"><code>ICommunicationObject</code></a> the potential exists to cause the disposal of the object to take an excessive amount of time in the event that there is an error or fault on the channel.</p> <p>Because of this, it is prescribed that you call the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.icommunicationobject.close.aspx" rel="nofollow noreferrer"><code>Close</code> method</a> and then call the <code>Dispose</code> method on <code>IDisposable</code>, using a number of catches for certain exception types and calling <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.icommunicationobject.abort.aspx" rel="nofollow noreferrer"><code>Abort</code></a> before you finally call <code>Dispose</code>.</p> <p>You can wrap this logic up in an <code>IDisposable</code> implementation which you can use in a <code>using</code> statement, as I've <a href="http://caspershouse.com/post/Using-IDisposable-on-WCF-Proxies-(or-any-ICommunicationObject-implementation).aspx" rel="nofollow noreferrer">outlined in a blog post on this matter</a>.</p> <p>The key here is to create a token that implements <code>IDisposable</code> and then in that implementation, call <code>Close</code>, catch the relevant exceptions, call <code>Abort</code> (if necessary) and then call <code>Dispose</code>.</p> <p>This is implemented as an extension method which returns an <code>IDisposable</code> on it which in turn allows you to use it in a <code>using</code> statement.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload