Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

IDisposable Works for WCF Services

4.00/5 (2 votes)
30 Jan 2011CPOL 22.8K  
IDisposable works for WCF services

WCF calls Dispose() on service implementations that implement IDisposable.

C#
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, 
                 ConcurrencyMode = ConcurrencyMode.Multiple)]
public class DataService : IDataService, IDisposable
{
  public void Dispose()
  {
     // Perform cleanup of your choice   
  }

  // IDataService implementation
  ...
  ...
}

Since I've found this useful on a number of occasions, I imagine it is of interest to others too ...

I haven't seen this documented anywhere, but then I haven't read everything either. :)

License

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