about uscontact

WCF Best Practices: How to Dispose WCF clients

Category:
Author: zemna
Date: April 17, 2021
Share this:

WCF Best Practices: How to Dispose WCF clients

Use of the using statement (Using in Visual Basic) is not recommended for Dispose WCF clients. This is because the end of the using statement can cause exceptions that can mask other exceptions you may need to know about.

[code lang="csharp"] using (CalculatorClient client = new CalculatorClient()) { ... } // <-- this line might throw Console.WriteLine("Hope this code wasn't important, because it might not happen.");

// The correct way to do it is: try { ... client.Close(); } catch (CommunicationException e) { ... client.Abort(); } catch (TimeoutException e) { ... client.Abort(); } catch (Exception e) { ... client.Abort(); throw; } [/code]

reference : http://blogs.microsoft.co.il/blogs/rotemb/archive/2008/07/30/WCF-Best-Practices_3A00_-How-to-Dispose-WCF-clients.aspx

Share this:

Leave a Reply

Your email address will not be published.

ZEMNA.NET

Professional software development agency estalished in Indonesia. We offers website setup, web application development, fulfillment service, and etc.
Follow us
Follow us to get latest news and tutorials.
2022 - Copyright, All Rights Reserved, Made by ZEMNA.NET with ❤️
magnifiercrossmenu