Expand Minimize

ReleaseInstanceMode Enumeration

Specifies when the system recycles the service object in the operation invocation process.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public enum ReleaseInstanceMode

Member nameDescription
AfterCallRecycles the object subsequent to the completion of the operation.
BeforeAndAfterCallRecycles the object prior to calling the operation and subsequent to the completion of the operation.
BeforeCallRecycles the object prior to calling the operation.
NoneRecycles the object according to the InstanceContextMode value.

Use the ReleaseInstanceMode with the ReleaseInstanceMode property to inform Windows Communication Foundation (WCF) that the current service object must be recycled at a particular point in the invocation process. The default behavior is to recycle a service object according to the InstanceContextMode value.

The following example code shows the use of ReleaseInstanceMode to recycle service objects both before and after a call.

class SampleService : ISampleService
{
  private Guid id;
  private string session;

  public SampleService()
  {
    id = Guid.NewGuid();
    session = OperationContext.Current.SessionId;
    Console.WriteLine("Object {0} has been created.", id);
    Console.WriteLine("For session {0}", session);
  }
  [OperationBehavior(
          ReleaseInstanceMode=ReleaseInstanceMode.BeforeAndAfterCall
  )]
  public string  SampleMethod(string msg)
  {
    Console.WriteLine("The caller said: \"{0}\"", msg);
    Console.WriteLine("For session {0}", OperationContext.Current.SessionId);
    return "The service greets you: " + msg;
  }

  ~SampleService()
  {
    Console.WriteLine("Object {0} has been destroyed.", id);
    Console.WriteLine("For session {0}", session);
  }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft