Message.TransactionId 屬性


取得訊息所屬交易的識別項。Gets the identifier for the transaction of which the message was a part.

 property System::String ^ TransactionId { System::String ^ get(); };
public string TransactionId { get; }
member this.TransactionId : string
Public ReadOnly Property TransactionId As String



與訊息相關聯之交易的識別項。The identifier for the transaction associated with the message.



未傳送訊息。The message has not been sent. 這個屬性只能在從佇列擷取的訊息中讀取。This property can only be read on messages retrieved from a queue.

-或--or- 篩選訊息佇列以忽略 TransactionId 屬性。The message queue is filtered to ignore the TransactionId property.


下列程式碼範例會顯示訊息的 TransactionId 屬性值。The following code example displays the value of a message's TransactionId property.


接收應用程式 TransactionId 會使用屬性來驗證訊息是否已作為特定交易的一部分傳送。Receiving applications use the TransactionId property to verify that a message was sent as part of a specific transaction. 交易識別碼包含傳送電腦的識別碼 (前16位) 後接4位元組的交易序號。The transaction identifier contains the identifier of the sending computer (first 16 bits) followed by a 4-byte transaction sequence number.

這個屬性僅適用于訊息佇列2.0 版和更新版本。This property is available only for Message Queuing version 2.0 and later.

交易識別碼不保證是唯一的,因為交易序號不是持續性,而且會以 2 20重新開始。Transaction identifiers are not guaranteed to be unique, because transaction sequence numbers are not persistent, and they start over again at 2 20. 訊息佇列只保證後續交易會有不同的交易序號。Message Queuing guarantees only that subsequent transactions will have different transaction sequence numbers.

您可以使用 TransactionId 屬性以及 IsFirstInTransactionIsLastInTransaction 屬性來驗證交易界限。You can use the TransactionId property along with the IsFirstInTransaction and IsLastInTransaction properties to verify transaction boundaries.