Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusing a WCF service client or creating one each time?

I heard (and read) a lot of opinions related to which is better: to reuse a WCF service client or create one each time. But I never managed to understand what exactly happens in those situations. And besides opinions, I really didn't find something 'official' (like a msdn page saying which is better, why and when).

In developping my own applications I rarely had problems with creating (and closing) one each time (the creating and closing proces didn't add in the processing time not even a milisecond). But in a few cases reusing a WCF service client really made a change (in a good way). These were observed by me in practice, without having a really logic motive.

So, can anyone explain me exactly which way is better? And in which situation? It depends on the client loading? Using Web Garden on IIS will affect the choice?

like image 311
Coral Doe Avatar asked Mar 09 '12 14:03

Coral Doe


1 Answers

Microsoft recommends caching for client creation: http://msdn.microsoft.com/en-us/library/aa738757.aspx (check out the 'issues to consider' part)

In the initial version of WCF there was a performance problem creating Channel Factory, therefore creating a client each time cause performance problems. We had to create and cache the channel factory. Microsoft fixed this problem with an update (.NET Framework SP1?) and caching is not necessary anymore.

Basically, the performance difference, after the fix, is negligible, especially considering that you're making a call over network.

like image 121
rosencreuz Avatar answered Oct 11 '22 02:10

rosencreuz