The one area of .NET that's always befuddled me is exactly when to implement the IDisposable pattern.
I have created a SOAP web service proxy using WSDL which implements IDisposable on the Component base class:
public partial class WSDLGeneratedProxy : System.Web.Services.Protocols.SoapHttpClientProtocol
I have created sort-of facade interface with simplified methods so that I could hide the service proxy interactions behind, and made it implement IDisposable:
public interface IServiceClient : IDisposable
I have an implementation of the IServiceClient and that implementation contains an actual member of WSDLGeneratedProxy
public class FacadeServiceClient : IServiceClient
{
private WSDLGeneratedProxy clientProxy;
}
So my question is - should I call the Dispose method on the service proxy explicitly? Is that the proper way to do it?
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (clientProxy != null)
{
clientProxy.Dispose();
}
}
}
Any suggestions or input is greatly appreciated.