In one of the WCF tutorials, I saw the following sample code:
Dim service as ...(a WCF service )
try
..
service.close()
catch ex as Exception()
...
service.abort()
end try
Is this the correct way to ensure that resources (i.e. connections) are released even under error conditions?
I've had good luck with this model:
See Indisposable: WCF Gotcha #1*, where he comes up with a convenient wrapper method:
Usage:
* Link removed as it appears to be malicious.
You've got the general idea correct. I've used the following extension method to keep the lines of repetitive code to a minimum.
Example of code using this extension method:
Of course this is C#, but I think that should still be of help.
If you use a client side cache, you might consider using Expression Trees (see http://thegrenade.blogspot.com/2009/07/using-expression-trees-for-more-elegant.html):
Usage: