I have an application that reuses the same WCF channel over and over again. I keep a static reference through a factory object. I wonder if this is good pratice or that I should
@Darin Dimitrov
Reuse the same proxy In many cases, you would want to reuse the same proxy. This has the best performance. It is especially true when you use security features since the initial security negotiation can have high cost.
proxy equals channel. if you look at this blog post, you can see the following code snippet:
ISimpleContract proxy = factory.CreateChannel();
((IClientChannel)proxy).Open();
Furthermore, if you plan to work with sessions, you don't want to establish a new session for each request (by creating a new channel/proxy each time).
You should use a single channel factory for all requests but different channels should be constructed for each request. Never reuse channels. They are not expensive to create and are not thread safe. What is expensive to create is the channel factory. It is thread safe and can be reused. Of course if the channel factory get into a faulted state you might need to reopen it.