Ensuring termination of a client session
Most WCF system bindings (such as NetTcpBinding and WSHttpBinding) support a session between the calling client and server. When the client side creates a new service proxy instance and invokes the service operation (or just opens the channel), there is a new session established between server and client. However, since WCF throttling adds a restriction on concurrent session numbers, if we keep instantiating new client proxies, the server will stop responding due to session exhaustion. Therefore, it is very important to take care of the session and make sure we properly terminate it after finishing the service invoking. This recipe will demonstrate the means to terminate the session appropriately.
How to do it...
WCF provides some useful properties in the OperationContractAttribute
that can help control session initializing and terminating. If our service consumer will always adopt an expected and determined calling pattern and process, we can use OperationContractAttribute...