共用方式為


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 值來回收服務物件。

適用於