Chapter 5. Instancing
WHAT'S IN THIS CHAPTER?
Using different InstanceContextModes
Controlling the Service Life time
Introducing Best Practices
Your proxy on the client side (typically derived from
ClientBase<T>) communicates with objects on the server side via the so-called channel stack. The service host accommodates these objects on the server side. As you will have learned in previous chapters, SOAP messages are exchanged between the proxy and the object on the server side. The
InstanceContextMode determines whether the client proxy now communicates with one and the same instance of the server object during a session (
PerSession), or whether a new instance is created every time the server object is used (
PerCall) and is then deleted again as soon as the method call is ended, or whether, last but not least, only one single server instance is created (
Single), irrespective of the number of clients.
There is an assumption in classical object-oriented applications that an instance of a class is created and used for work or communication for a certain length of time. If certain properties are set for the object beforehand, they remain in place while there is a valid reference to the object, and the methods which are called up can work with the values which are set beforehand. If the
Dispose method is called and the object reference is set to
null, important resources are released, and the object can be ...