Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does WCF4 (.NET Framework 4) supports client connection pooling?

So the question is does WCF4 invokes client connection pooling to WCF-service? For instance, we have ASP .NET application as client and service (on separate machines). Then somewhere in code we have something like that:

ServiceClient client = new ServiceClient();
// Here some work with service goes...

Lets say we have another service invoke in anither piece of code:

ServceClient client2 = new ServiceClient();
// Another one processing...

So will client2 connection taken from connection pool?

like image 346
kseen Avatar asked Nov 01 '11 10:11

kseen


2 Answers

The "pooling" is dependent on used transport protocol. For HTTP the WCF by default uses HTTP persistent connections which live for short period of time (they are closed after 100s of inactivity) and can be reused by subsequent requests (even from different proxy instance). For TCP and Named pipes WCF provides built-in pooling.

like image 121
Ladislav Mrnka Avatar answered Sep 29 '22 15:09

Ladislav Mrnka


Why would you do that? WCF can accept multiple Requests over one Client with ConcurrencyMode.Multiple. So it wouldn't make much sense to initialize two Clients..

WCF ServiceContract has three important Attributes for this behaviour,

InstanceContextMode

  • PerSession (Creates per Session an Instance of the Service)
  • Single (Creates Single Instance for every Client)
  • PerCall (Creates per Call an Instance of the Service)

ConcurrencyMode

  • Multiple (Client can make multiple calls at the same time -> Multithreaded)
  • Single (Client can make one call and other have to wait until the other call finished)
  • Reentrant (Client can make multiple calls at the same time, i don't know exactly but i think it was like if one call uses another wcf service, another call can be processed until the other wcf service call is completed, so it releases the lock between time of wcf service call is made and response)

SessionMode

  • Allowed (Client can use a Session but don't have to)
  • NotAllowed (Client can't use a Session)
  • Required (Client have to use Session)

Most time I use InstanceContextMode.PerSession (Because Client 1 doesnt have access to the Variables in the Service of Client 2), ConcurrencyMode.Multiple and SessionMode.Required.

You can also specify how many Instances can be initialized, how many Concurrent Calls can be made and how many Session can be used.

like image 42
RaphaelH Avatar answered Sep 29 '22 14:09

RaphaelH