¿Reutilizar un cliente de servicio WCF o crear uno cada vez?

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?

preguntado el 09 de marzo de 12 a las 14:03

1 Respuestas

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.

respondido 09 mar '12, 15:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.