Click here to Skip to main content
12,511,920 members (43,367 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.2K views
4 bookmarked
Posted

Do not use "using" for WCF Clients

, 18 May 2011 CPOL
Good Tip, got my 5!As an alternative to your tip, when using generated proxies you could also add the logic to a partial class with the same name as the proxy class, see below.public partial class MyGeneratedProxyClient : IDisposable{ void IDisposable Dispose() { try...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

22 May 2011
Jeremy Hutchinson
Or you can use T4 to generate a static class wrapper around the service. Then your call can look like this:SvcWrapper.Login(username, password);The full explanation and sample code is located here[^].
17 May 2011
Omar Al Zabir
2 alternatives  
Traditional using() block disposes WCF clients incorrectly when there's a communication exception, eg dropping network connection. It raises exception during the dispose and thus the resources held by the WCF client aren't released properly. After some time, you end up with memory leaks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Patrick Kalkman
Architect http://www.simpletechture.nl
Netherlands Netherlands
Patrick Kalkman is a senior Software Architect with more than 20 years professional development experience. He works for SimpleTechture where he helps teams develop state of the art web applications.

Patrick enjoys writing his blog. It discusses agile software development. Patrick can be reached at patrick@simpletechture.nl.

Published Windows 8 apps:

Published Windows Phone apps:

Awards:

Best Mobile article of March 2012
Best Mobile article of June 2012

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 18 May 2011
Article Copyright 2011 by Patrick Kalkman
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid