OperationContractAttribute.IsTerminating 屬性

定義

取得或設定值,這個值表示服務作業在傳送回覆訊息 (如果有的話) 之後,是否導致伺服器關閉該工作階段。Gets or sets a value that indicates whether the service operation causes the server to close the session after the reply message, if any, is sent.

public:
 property bool IsTerminating { bool get(); void set(bool value); };
public bool IsTerminating { get; set; }
member this.IsTerminating : bool with get, set
Public Property IsTerminating As Boolean

屬性值

Boolean

如果作業會導致伺服器關閉工作階段,則為 true,否則為 falsetrue if the operation causes the server to close the session, otherwise, false. 預設為 falseThe default is false.

範例

下列範例是一個實作服務合約的服務,此合約指定三個作業。The following example is a service that implements a service contract that specifies three operations. 此服務需要一個可設定狀態的連線。The service requires a stateful connection. 若呼叫者先呼叫其他作業,而非 MethodOne,通道會拒絕並擲回例外狀況。If a caller's first call is to any operation other than MethodOne, the channel is refused and an exception is thrown. 當呼叫者呼叫 MethodOne 以初始化工作階段時,該呼叫者隨時可呼叫 MethodThree 終止通訊工作階段。When a caller initiates a session by calling MethodOne, that caller can terminate the communication session at any time by calling MethodThree. MethodTwo 可以在會話期間呼叫任意次數。MethodTwo can be called any number of times during a session.

[ServiceContractAttribute(SessionMode=SessionMode.Required)]  
public class InitializeAndTerminateService  
{  
  [OperationContract(  
    IsOneWay=true,  
    IsInitiating=true,  
    IsTerminating=false  
  )]  
  public void MethodOne()  
  {  
    return;  
  }  

  [OperationContract(  
    IsInitiating=false,  
    IsTerminating=false  
  )]  
  public int MethodTwo(int x, out int y)  
  {  
    y = 34;  
    return 0;  
  }  

  [OperationContract(  
    IsOneWay=true,  
    IsInitiating=false  
    IsTerminating=true  
  )]  
  public void MethodThree()  
  {  
    return;  
  }  
}  

備註

使用 IsTerminating 屬性,表示呼叫某個服務作業會終止通訊工作階段。Use the IsTerminating property to indicate that calling a service operation terminates the communication session.

在用戶端應用程式中,設定的值會 IsTerminating true 指示 WCF 在回復抵達之後關閉通道。In a client application, a value of IsTerminating set to true instructs WCF to close the channel after the reply arrives.

服務中會設定計時器,若用戶端沒有在該時段內關閉通道,通道就會中止。In a service, a timer is set and the channel aborts if the client does not close the channel within that period.

如需搭配使用此屬性與會話的詳細資訊,請參閱 使用會話For more information about using this property with sessions, see Using Sessions.

注意

如果呼叫者正在接聽 OperationContext.OperationCompleted 作業的 OperationContractAttribute.IsTerminating 事件,當收到回應時,它可能會封鎖。If a caller is listening for the OperationContext.OperationCompleted event for an OperationContractAttribute.IsTerminating operation, it is possible to block when the response is received. 處理這種情況的正確方式是,當引發 OperationCompleted 時在另一個執行緒上排程工作,然後立即從該事件處理常式傳回。The proper way to handle this is to schedule work on another thread when OperationCompleted is raised and then immediately return from that event handler.

適用於