Creating and Managing SIP Transactions
The Microsoft.Rtc.Sip namespace defines a base type, Transaction, to represent the basic properties of a SIP transaction. This includes the request that originated the transaction, any responses handled by the transaction, and events for catching transaction status changes (such as time-outs or cancellations).
Two types derive from Transaction: ClientTransaction, which represents a client transaction; and ServerTransaction, which represents a server transaction.
The ServerTransaction instance is obtained by referencing the RequestReceivedEventArgs.ServerTransaction property, available when a RequestReceivedEventArgs object is dispatched to the designated method. The request it was created to service can be obtained in two ways: one, as the RequestReceivedEventArgs.Request property; or two, as the ServerTransaction.Request property.
Client transactions must be created programmatically by calling ServerTransaction.CreateBranch. The UAC case, in which a client transaction originates a request and does not have a parent server transaction, is not supported.
To fork a message, ServerTransaction.CreateBranch can be called as many times as forks are needed. To send a request to each fork, call ClientTransaction.SendRequest on each branch.
Responses to serviced requests are obtained by registering a handler for the ClientTransaction.ResponseReceived event. When this event is raised, any response received by Microsoft Lync Server 2010 that matches the originating request will be sent as a ResponseReceivedEventArgs object to the method registered using the ResponseReceivedEventHandler delegate.
Responses can also be raised by dispatches from the message filter script when it is set to filter responses. In this case, the response will be out-of-context—"there is no ClientTransaction object on the server that originated the request. In this case, the new ClientTransaction object is obtained by referencing the ResponseReceivedEventArgs.ClientTransaction property. The ServerTransaction to forward the response is obtained by referencing the ClientTransaction.ServerTransaction property on this ClientTransaction, which contains the new ServerTransaction instance to handle it.
If a CANCEL method is received for a transaction, the Transaction.Canceled event is raised. When the transaction is closed, Transaction.Terminated is raised. If a transaction times out, Transaction.TimedOut is raised.