380 likes | 518 Views
WCF INSTANCE MANAGEMENT Dhananjay Kumar MVP-Connected Syste m. Instance Management. Instance Management is a technique to decide, which SERVICE INSTANCE handles which CLIENT REQUEST and when? This is a service side implementation detail
E N D
WCF INSTANCE MANAGEMENT Dhananjay Kumar MVP-Connected System
Instance Management • Instance Management is a technique to decide, which SERVICE INSTANCE handles which CLIENT REQUEST and when? • This is a service side implementation detail • This is useful to decide scalability, performance, durability, transactions and queued calls
Instance Management BEHAVIOR • Instance management is a service side activation implementation detail that should not get manifested to the client. WCF achieve this by BEHAVIOR. • A Behavior is a local attribute of service that does not affect its communication patterns. • Client does not aware of the Behavior. • Service does not manifest behavior in binding or metadata. • Practically Behaviors are WCF classes. • These are used at the runtime operations.
Instance Management BEHAVIOR
Instance Management SERVICE BEHAVIOR • This applies directly to service implementation class. • This affects all the endpoints. • This is used to configure service instance mode.
Instance Management OPERATION BEHAVIOR • This is used to configure operation behavior. • This affects only implementation of a particular operation. • This could apply only to method that implements contract operation. • This is not applied to the contract definition itself.
Instance Management Per Call Instance Mode Every Client request gets a new dedicated service instance. A service instance exists only when a client call is in progress.
Instance Management Per Call Instance Mode
Instance Management Per Call Instance Mode
Instance Management Per Call Instance Mode Demo
Instance Management Per Session Instance Mode
Instance Management Per Session Instance Mode
Instance Management Per Session Instance Mode • WCF can maintain a logical session between a client and service. • The service instance remains in the memory throughout the session. • The client session is per service endpoint per proxy.
Instance Management Configuring Session full Service
Instance Management Behavior Facets The Behavior part is required, so that WCF will keep the Service Instance Context alive throughout the session.
Instance Management Behavior Facets • InstanceContextMode.PerSession is default value for InstanceContextmode property. • The session terminates when client closes the proxy. • Proxy has to notify the service that session has been closed and service calls the Dispose () method on worker thread.
Instance Management Contract Facets In order to create all messages from a particular client to a particular instance WCF needs to identify the client and this is done by TRANSPORT SESSION
Instance Management Contract Facets • For this ServiceContract attribute having a property called SessionMode. • Type of property SessionMode is enumSessionMode. • It is inside namespace System.ServiceModel. • Property SessionMode is a public property. • SessionModeenum is default to SessionMode.Allowed. • The Configured value of SessionMode is exposed to client in MetaData.
Instance Management Contract Facets
Instance Management SessionMode.Allowed • When the SessionMode is configured with SessionMode.Allowed, transport session are allowed but not enforced. • The Behavior of service will depend upon behavior configuration and binding.
Instance Management SessionMode.Allowed
Instance Management SessionMode.Required • SessionMode.Required value restricts to use Transport level session. • If a contract is configured as SessionMode.Required with a service end point who's binding does not maintain a Transport level session a Run time error will encountered at loading of service.
Instance Management SessionMode.Required
Instance Management SessionMode.Required
Instance Management SessionMode.NotAllowed • This disallows the use of Transport session. • Regardless of the service configuration, when SessionMode.NowAllowed is configured at contract, the service will always behave as Per-call service.
Instance Management SessionMode.NotAllowed
Instance Management SessionMode.NotAllowed DEMO
Instance Management Singleton Instance Mode
Instance Management Singleton Instance Mode
Instance Management Singleton Instance Mode • The Singleton Service Instance created only once. • It created when the service host is created. • It lives forever. • It got disposed only when host shuts down. • Singleton service instance does not require client to maintain any logical session. • It does not required to use binding that supports transport level session.
Instance Management Singleton Instance Mode
Instance Management Singleton Instance Mode • Having scalability problem. • All requests to service will run on different worker thread, so it will cause synchronization problem. • Only one client could have access to singleton service instance at a time. It will decrease throughput of the service. • Responsiveness is very low • Singleton Service instance should only be used, when no other options are available. For instance Global Log Book, Single Communication Port etc.
Instance Management Singleton Instance Mode DEMO
Thank You. Dhananjay Kumar MVP-Connected System