I heard that it’s essential to Dispose (or Close) a WCF client proxy even when
- you’re not using sessions
- there are no unmanaged resources that need deterministic clean up (e.g. open sockets)
For example, when using a BasicHttpBinding with the default binding configuration, this should be fine even in a popular web page, right?
var clt = new MyServiceClient();
clt.PlaceOrder(foo);
// no dispose
or
var clt = new ChannelFactory<IOrderService>().CreateChannel();
clt.PlaceOrder(foo);
Thanks
Creating a ChannelFactory & Opening it is an expensive operation and you should avoid doing it for every call if you care performance.
Your first usecase is not right even with basicHttpBinding because it will potentially create a new channelfactory for each instantation. .NET 3.5 SP1 has introduced some ChannelFactory caching so you might be ok in certain scenarios.
In your 2nd usecase, if you cache and reuse the channelfactory, disposing isn’t really nesseaary but keep in mind you/your deployment guy can change the binding @ deployment time and lack of closing/disposing can have a huge impact.
In summary it’s always safe to close/dispose and that’s why MSDN suggest that.