DCSIMG
WCF Best Practices: How to Dispose WCF clients - Rotem Bloom's Blog

Rotem Bloom's Blog

Share knowledge on .NET and web development

News

About Me

Glad to help and share knowledge on .NET and also huge fan of Dream Theater.

Contact me via messenger

View Rotem Bloom's profile on LinkedIn

Dream Theater Pics

Blogs I Read

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.

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;
}

Comments

WCF Best Practices: How to Dispose WCF clients | Development Zemna.Net said:

Pingback from  WCF Best Practices: How to Dispose WCF clients | Development Zemna.Net

# December 13, 2010 11:04 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: