Indigo has the ability to mark specific methods on a contract as being initiating or terminating methods for the contract. If a method is marked as being an IsInitiating method then this means that this method can be used as the first method called onto the contract, if the IsInitiating is set as false then this method cannot be used as the initiating method onto the contract. This means it is possible to setup a contract and define the calling behavior onto the contract, for both the start and the end of the session.
These mechanisms are only useful inside a session based system and will not work if there is no session on the underlying channel. Sessions are enabled whenever reliable messaging is enabled.
The IsTerminating flag marks a method as being the last method called in a session, so if this method is called the channel is effectively closed and the session terminated. When the IsTerminating is used there is no need to close the channel afterwards on the client side of the system since it is already closed.
These can be kind of used as constructor and destructor items on the service, although they will not be called as constructors and destructors. If you want to use a contrustructor or destructor, you should see my previous blog entry where I describe how to use IContractDispatcher interface to hook into the events in the system.
I should talk about sessions in another blog 🙂
public interface IMyContract
[OperationContract(IsInitiating = true)]
[OperationContract(IsInitiating = false)]
[OperationContract(IsTerminating = true)]