Why is it important to dispose/close a WCF client proxy

后端 未结 1 449
感情败类
感情败类 2021-02-15 10:21

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 dete
1条回答
  •  别那么骄傲
    2021-02-15 10:59

    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.

    0 讨论(0)
提交回复
热议问题