ReleaseInstanceMode 枚举

定义

指定系统在操作调用进程中回收服务对象的时间。

public enum class ReleaseInstanceMode
public enum ReleaseInstanceMode
type ReleaseInstanceMode = 
Public Enum ReleaseInstanceMode
继承
ReleaseInstanceMode

字段

AfterCall 2

在完成操作后回收对象。

BeforeAndAfterCall 3

在调用操作前和完成操作后回收对象。

BeforeCall 1

在调用操作前回收对象。

None 0

根据 InstanceContextMode 值回收对象。

示例

下面的代码示例演示如何使用 ReleaseInstanceMode 在调用之前和之后均回收服务对象。

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);
  }
}
Friend Class SampleService
    Implements ISampleService
  Private id As Guid
  Private session As String

  Public Sub New()
    id = Guid.NewGuid()
    session = OperationContext.Current.SessionId
    Console.WriteLine("Object {0} has been created.", id)
    Console.WriteLine("For session {0}", session)
  End Sub
  <OperationBehavior(ReleaseInstanceMode:=ReleaseInstanceMode.BeforeAndAfterCall)> _
  Public Function SampleMethod(ByVal msg As String) As String Implements ISampleService.SampleMethod
    Console.WriteLine("The caller said: ""{0}""", msg)
    Console.WriteLine("For session {0}", OperationContext.Current.SessionId)
    Return "The service greets you: " & msg
  End Function

  Protected Overrides Sub Finalize()
    Console.WriteLine("Object {0} has been destroyed.", id)
    Console.WriteLine("For session {0}", session)
  End Sub
End Class

注解

ReleaseInstanceMode将 与 属性一起使用ReleaseInstanceMode可通知 Windows Communication Foundation (WCF) 必须在调用过程中的特定点回收当前服务对象。 默认行为是根据 InstanceContextMode 值来回收服务对象。

适用于