Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single WCF channel performance vs multiple channels

Tags:

c#

wcf

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 open x channels and round robin all services calls over these channels instead of using the single channel?

Do these services calls get queued if using only 1 channel or does the same happen when I would use x channels?

like image 395
Bjorn Bailleul Avatar asked Sep 02 '11 09:09

Bjorn Bailleul


2 Answers

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.

like image 101
Darin Dimitrov Avatar answered Nov 01 '22 15:11

Darin Dimitrov


@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).

like image 23
DELUXEnized Avatar answered Nov 01 '22 14:11

DELUXEnized