Does WCF4 (.NET Framework 4) support client pooling?

So the question is, does WCF4 include client pooling in a WCF service? For example, we have an ASP.NET application as a client and a service (on separate machines). Then somewhere in the code there is something like this:

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

Suppose we have another service link in any part of the code:

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

So will there be a client2 connection from the connection pool?

+8
c # web-services connection-pooling wcf
source share
2 answers

"Association" depends on the transport protocol used. For HTTP, WCF by default uses HTTP persistent connections that live for a short period of time (they close after 100 years of inactivity ) and can be reused by subsequent requests (even from different proxy instances). WCF provides an embedded pool for TCP and named pipes.

+15
source share

Why would you do this? WCF can accept multiple requests per client using ConcurrencyMode.Multiple . Therefore, it would not make sense to initialize two Clients.

WCF ServiceContract has three important attributes for this behavior:

InstanceContextMode

  • PerSession (creates a service instance for each session)
  • Single (creates a single instance for each client)
  • PerCall (created to invoke a service instance)

ConcurrencyMode

  • Multiple (Client can make several calls simultaneously β†’ Multithreading)
  • Single (the client can make one call, and the other must wait for the completion of another call)
  • Reentrant (the client can make several calls at the same time, I don’t know for sure, but I think that if one call uses another wcf service, the other call can be processed until the other wcf service call is completed, so it releases the lock between wcf service call time and response)

Sessionmode

  • Allowed (client can use session, but not required)
  • NotAllowed (client cannot use session)
  • Required (client must use session)

In most cases, I use InstanceContextMode.PerSession (since client 1 does not have access to variables in client service 2), ConcurrencyMode.Multiple and SessionMode.Required .

You can also specify how many instances can be initialized, how many simultaneous calls, and how many sessions you can use.

+2
source share

All Articles