tags:

views:

32

answers:

3

I have recently come across the term Instance Deactivation.

a) What is that?

b) What for we need that?

c) In what context will it be useful?

I am looking for a simple answer that can be easily undestandable and if posible with some pseudo code.

Thanks

+1  A: 

Basically I take to mean that the instance of the class that the service operation is being called on is not torn down. If you have per call activation then a new instance of the service class will be created each time you call an operation on the service. After the method ends then that instance of the class will be disposed.

If you want to improve performance say at the expense of scalability then you would not deactivate the instance and thus choose a different instance activation scheme.

This MSDN artice : Discover Mighty Instance Management Techniques For Developing WCF Apps together with the link in @SteveCav answer provide good references.

Preet Sangha
Sir your explanation is nice but I literally didnot understand. In a more simple term if you can explain, it will be better. I am basically new to WCF
priyanka.sarkar_2
Like a) service operation is being called on is not torn downb) per call activation .. What is it?Please explain
priyanka.sarkar_2
+3  A: 

When a WCF method is invoked, it is passed to a service instance.

Instance Deactivation simply refers to the moment where the WCF system disposes of this instance.

In a Per-Call Service, instance deactivation will occur after each method call.

In a Per-Session Service, instance deactivation will occur when the client calls Close on the proxy, or when the transport-session's inactivity timeout is reached.

In a Singleton Service, instance deactivation will occur when the Service Host is closed.

You can also configure individual service methods to trigger instance deactivation:.

[OperationBehavior(ReleaseInstanceMode = ReleaseInstanceMode.AfterCall)]
 public void MyMethodWhichTriggersAnAutomaticRelease()
 {
     // ...
 }

As well as this, you can manually trigger a service instance release:

public void MyMethodWhichTriggersAManualRelease()
{
     OperationContext.Current.InstanceContext.ReleaseServiceInstance();
}

Juval Lowy has this to say on whether you should manually override the standard instance deactivation mechanisms:

Instance deactivation is an optimization technique, and like all optimization techniques, you should avoid it in the general case. Consider using instance deactivation only after failing to meet both your performance and scalability goals and when careful examination and profiling has proven beyond a doubt that using instance deactivation will improve the situation.

Andrew Shepherd