Redigera

Dela via


OperationContractAttribute.IsTerminating Property

Definition

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

Property Value

true if the operation causes the server to close the session, otherwise, false. The default is false.

Examples

The following example is a service that implements a service contract that specifies three operations. The service requires a stateful connection. If a caller's first call is to any operation other than MethodOne, the channel is refused and an exception is thrown. When a caller initiates a session by calling MethodOne, that caller can terminate the communication session at any time by calling MethodThree. 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;  
  }  
}  

Remarks

Use the IsTerminating property to indicate that calling a service operation terminates the communication session.

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.

Note

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. 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.

Applies to