The short answer is that with Web Service Proxy Classes, you should Close them and not Dispose them.
In almost every case you should dispose of things that implement IDisposable. However, Web Service Proxy classes are a special case. With these classes, and all classes that inherit from System.ServiceModel.ClientBase
, it is a best practice to not call dispose but to call the Close method directly.
Using reflector, you can see that the Dispose
method of ClientBase
simply calls Close
. So if there are no exceptions, Dispose
and Close
will do the same thing. However if there is an exception, there will be different behaviors.
Because the Close
method can throw exceptions, you should call it directly and catch it's exception. If you call the Dispose
method, you should also catch the exceptions, but your code will be harder to understand.
This also means that you should avoid putting the declaration of the proxy in a using
statement. In this case, if an exception is thrown in the using
block, it will be obscured. The Dispose
call that is auto generated by the using
block will get called because it is in a finally
block. The exception that is thrown from the Close
in the Dispose
will obscure whatever exception was previously thrown.
To see more detailed explinations, read these articles on MSDN, Coding Up Style, BlogginAbout.Net, and StackOverflow.
For the backstory on why it is implemented this way, check on this thread on the MSDN forums.