Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF CreateChannel for every method call

Tags:

wcf

In my current web project, we perform a ClientFactory.CreateChannel for every method call to a remote service.

Is this really necessary? What is the best practice?

like image 781
AllWorkNoPlay Avatar asked Oct 26 '10 13:10

AllWorkNoPlay


1 Answers

This depends to some extent what your requirements are. Opening a channel is expensive, relatively speaking. Best practice is to have the class that is doing the remote calls implement IDisposable, it should make a call to ClientFactory.CreateChannel once, use the channels in all the method calls, and close the channel when the Dispose method is called. That said, if the time between the calls to methods that call to a remote service is long (longer then the default idle timeout on the channel which is 10 minutes) then doing a ClientFactory.CreateChannel isn't particularly harmful, but I would say it would still be better to go the IDisposable route and encapsulate use of the class with the 'using' keyword

like image 167
Steve Ellinger Avatar answered Oct 21 '22 02:10

Steve Ellinger