65.9K
CodeProject is changing. Read more.
Home

IDisposable Works for WCF Services

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (2 votes)

Jan 30, 2011

CPOL
viewsIcon

22811

IDisposable works for WCF services

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

[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. :)