Export (0) Print
Expand All

OperationContractAttribute.IsInitiating Property

Gets or sets a value that indicates whether the method implements an operation that can initiate a session on the server (if such a session exists).

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

'Declaration
Public Property IsInitiating As Boolean

Property Value

Type: System.Boolean
true if the operation is permitted to initiate a session on the server, otherwise, false. The default is true.

The IsInitiating property controls whether an operation can be the first operation called when a session is created.

NoteNote

The value of ServiceContractAttribute.SessionMode must be either Allowed or Required and the binding used must require or allow sessions for the IsInitiating property to work properly.

The default is true, which means that an operation can be the first one called on a channel. Subsequent calls to the initiating method have no effect, other than to call the method. No other sessions are created. If the contract does not make use of a session, setting IsInitiating to false is ignored.

Typically, you set IsInitiating to false to force clients to call another method on the service before they can invoke this one. For example, if your service has a series of operations that depend on an order ID number, you can set IsInitiating to true for a GetOrderId service operation and set all remaining service operations to false. This ensures that each new client obtains an order ID prior to using the other methods exposed by the service.

NoteNote

There is an interaction between IsInitiating and the Action property. A service contract can have only one service operation with the Action property set to "*". Any group of service contracts hosted at the same listen URI that a service class implements can have many service operations with the Action property set to "*" when the IsInitiating property is set to false. However, only one of those service methods can have the Action property set to "*" and the IsInitiating property set to true.

If a service receives a message for a non-initiating operation, the service returns an ActionNotSupported SOAP fault. The client experiences this as an FaultException. If a client calls a non-initiating operation first, the client runtime throws an System.InvalidOperationException.

For more information, see Using Sessions.

The following example is a service that implements a service contract that specifies three methods. The service requires a session. 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.

[ServiceContract(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;
  }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 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.

Show:
© 2014 Microsoft