private void ConfigureEnlistment(WsatRegistrationHeader header)
        {
            Enlistment enlistment = new Enlistment();
            string contextId = header.ContextId;
            if (contextId == null)
            {
                contextId = CoordinationContext.CreateNativeIdentifier(header.TransactionId);
            }
            enlistment.LocalTransactionId = header.TransactionId;
            enlistment.RemoteTransactionId = contextId;
            Notifications twoPhaseCommit = Notifications.TwoPhaseCommit;
            switch (this.protocol)
            {
                case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Volatile2PC:
                    twoPhaseCommit |= Notifications.Volatile | Notifications.Phase0;
                    break;

                case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Durable2PC:
                    break;

                default:
                    Microsoft.Transactions.Bridge.DiagnosticUtility.FailFast("Invalid protocol");
                    break;
            }
            enlistment.NotificationMask = twoPhaseCommit;
            enlistment.ProtocolProviderContext = this;
            base.enlistment = enlistment;
        }
Exemple #2
0
        public void MarshalAsCoordinationContext(Transaction transaction, out CoordinationContext context, out RequestSecurityTokenResponse issuedToken)
        {
            uint                    num;
            IsolationFlags          flags;
            string                  str2;
            WsatExtendedInformation information;
            string                  str3;
            Guid                    distributedIdentifier = transaction.TransactionInformation.DistributedIdentifier;
            string                  contextId             = null;

            context = new CoordinationContext(this.protocolVersion);
            OleTxTransactionFormatter.GetTransactionAttributes(transaction, out num, out flags, out str2);
            context.IsolationFlags = flags;
            context.Description    = str2;
            if (TransactionCache <Transaction, WsatExtendedInformation> .Find(transaction, out information))
            {
                context.Expires = information.Timeout;
                if (!string.IsNullOrEmpty(information.Identifier))
                {
                    context.Identifier = information.Identifier;
                    contextId          = information.Identifier;
                }
            }
            else
            {
                context.Expires = num;
                if (context.Expires == 0)
                {
                    context.Expires = (uint)TimeoutHelper.ToMilliseconds(this.wsatConfig.MaxTimeout);
                }
            }
            if (context.Identifier == null)
            {
                context.Identifier = CoordinationContext.CreateNativeIdentifier(distributedIdentifier);
                contextId          = null;
            }
            if (!this.wsatConfig.IssuedTokensEnabled)
            {
                str3        = null;
                issuedToken = null;
            }
            else
            {
                CoordinationServiceSecurity.CreateIssuedToken(distributedIdentifier, context.Identifier, this.protocolVersion, out issuedToken, out str3);
            }
            AddressHeader refParam = new WsatRegistrationHeader(distributedIdentifier, contextId, str3);

            context.RegistrationService = this.wsatConfig.CreateRegistrationService(refParam, this.protocolVersion);
            context.IsolationLevel      = transaction.IsolationLevel;
            context.LocalTransactionId  = distributedIdentifier;
            if (this.wsatConfig.OleTxUpgradeEnabled)
            {
                context.PropagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
            }
        }
        public ParticipantEnlistment(ProtocolState state, WsatRegistrationHeader header, Microsoft.Transactions.Wsat.Messaging.ControlProtocol protocol, TwoPhaseCommitParticipantProxy proxy) : base(state)
        {
            this.protocol = protocol;
            proxy.AddRef();
            this.participantProxy = proxy;
            this.ConfigureEnlistment(header);
            this.CreateCoordinatorService();
            switch (protocol)
            {
                case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Volatile2PC:
                    base.stateMachine = new VolatileStateMachine(this);
                    base.stateMachine.ChangeState(state.States.VolatileRegistering);
                    return;

                case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Durable2PC:
                    base.stateMachine = new DurableStateMachine(this);
                    base.stateMachine.ChangeState(state.States.DurableRegistering);
                    return;
            }
            Microsoft.Transactions.Bridge.DiagnosticUtility.FailFast("Invalid protocol");
        }
        //=======================================================================================
        // The demand is not added now (in 4.5), to avoid a breaking change. To be considered in the next version.
        /*
        // We demand full trust because we use CoordinationContext and CoordinationServiceSecurity from a non-APTCA assembly.
        // The CoordinationContext constructor can call Environment.FailFast and it's recommended to not let partially trusted callers to bring down the process.
        // WSATs are not supported in partial trust, so customers should not be broken by this demand.
        [PermissionSet(SecurityAction.Demand, Unrestricted = true)]
        */
        public void MarshalAsCoordinationContext(Transaction transaction,
                                                 out CoordinationContext context,
                                                 out RequestSecurityTokenResponse issuedToken)
        {
            Guid transactionId = transaction.TransactionInformation.DistributedIdentifier;
            string nonNativeContextId = null;

            context = new CoordinationContext(this.protocolVersion);

            // Get timeout, description and isolation flags
            uint timeout;
            IsolationFlags isoFlags;
            string description;
            OleTxTransactionFormatter.GetTransactionAttributes(transaction,
                                                               out timeout,
                                                               out isoFlags,
                                                               out description);
            context.IsolationFlags = isoFlags;
            context.Description = description;

            // If we can, use cached extended information
            // Note - it may be worth using outgoing contexts more than once.
            // We'll let performance profiling decide that question
            WsatExtendedInformation info;
            if (WsatExtendedInformationCache.Find(transaction, out info))
            {
                context.Expires = info.Timeout;

                // The extended info cache only contains an identifier when it's non-native
                if (!string.IsNullOrEmpty(info.Identifier))
                {
                    context.Identifier = info.Identifier;
                    nonNativeContextId = info.Identifier;
                }
            }
            else
            {
                context.Expires = timeout;
                if (context.Expires == 0)
                {
                    // If the timeout is zero, there are two possibilities:
                    // 1) This is a root transaction with an infinite timeout.
                    // 2) This is a subordinate transaction whose timeout was not flowed.
                    // We have no mechanism for distinguishing between the two cases.
                    //
                    // We could always return zero here, instead of using the local max timeout.
                    // The problem is that the 2004/08 WS-C spec does not specify the meaning
                    // of a zero expires field. While we accept zero to mean "as large as possible"
                    // it would be risky to expect others to do the same.  So we only propagate
                    // zero in the expires field if the local max timeout has been disabled.
                    //
                    // This is MB 34596: how can we flow the real timeout?
                    context.Expires = (uint)TimeoutHelper.ToMilliseconds(this.wsatConfig.MaxTimeout);
                }
            }

            if (context.Identifier == null)
            {
                context.Identifier = CoordinationContext.CreateNativeIdentifier(transactionId);
                nonNativeContextId = null;
            }

            string tokenId;
            if (!this.wsatConfig.IssuedTokensEnabled)
            {
                tokenId = null;
                issuedToken = null;
            }
            else
            {
                CoordinationServiceSecurity.CreateIssuedToken(transactionId,
                                                              context.Identifier,
                                                              this.protocolVersion,
                                                              out issuedToken,
                                                              out tokenId);
            }

            AddressHeader refParam = new WsatRegistrationHeader(transactionId, nonNativeContextId, tokenId);
            context.RegistrationService = wsatConfig.CreateRegistrationService(refParam, this.protocolVersion);
            context.IsolationLevel = transaction.IsolationLevel;
            context.LocalTransactionId = transactionId;

            if (this.wsatConfig.OleTxUpgradeEnabled)
            {
                context.PropagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
            }
        }
 private TransactionContext CreateTransactionContext()
 {
     Microsoft.Transactions.Bridge.EnlistmentOptions enlistmentOptions = this.enlistment.EnlistmentOptions;
     string remoteTransactionId = this.enlistment.RemoteTransactionId;
     Guid localTransactionId = this.enlistment.LocalTransactionId;
     CoordinationContext context = new CoordinationContext(this.state.ProtocolVersion) {
         Expires = (enlistmentOptions.Expires == TimeSpan.MaxValue) ? uint.MaxValue : ((uint) ((int) enlistmentOptions.Expires.TotalMilliseconds)),
         Identifier = remoteTransactionId,
         LocalTransactionId = localTransactionId,
         IsolationLevel = enlistmentOptions.IsoLevel,
         IsolationFlags = enlistmentOptions.IsolationFlags,
         Description = enlistmentOptions.Description
     };
     string contextId = CoordinationContext.IsNativeIdentifier(remoteTransactionId, localTransactionId) ? null : remoteTransactionId;
     string sctId = null;
     RequestSecurityTokenResponse issuedToken = null;
     if (this.state.Config.PortConfiguration.SupportingTokensEnabled)
     {
         CoordinationServiceSecurity.CreateIssuedToken(localTransactionId, remoteTransactionId, this.state.ProtocolVersion, out issuedToken, out sctId);
     }
     AddressHeader refParam = new WsatRegistrationHeader(localTransactionId, contextId, sctId);
     context.RegistrationService = this.state.RegistrationCoordinatorListener.CreateEndpointReference(refParam);
     return new TransactionContext(context, issuedToken);
 }
Exemple #6
0
        //=======================================================================================
        // The demand is not added now (in 4.5), to avoid a breaking change. To be considered in the next version.

        /*
         * // We demand full trust because we use CoordinationContext and CoordinationServiceSecurity from a non-APTCA assembly.
         * // The CoordinationContext constructor can call Environment.FailFast and it's recommended to not let partially trusted callers to bring down the process.
         * // WSATs are not supported in partial trust, so customers should not be broken by this demand.
         * [PermissionSet(SecurityAction.Demand, Unrestricted = true)]
         */
        public void MarshalAsCoordinationContext(Transaction transaction,
                                                 out CoordinationContext context,
                                                 out RequestSecurityTokenResponse issuedToken)
        {
            Guid   transactionId      = transaction.TransactionInformation.DistributedIdentifier;
            string nonNativeContextId = null;

            context = new CoordinationContext(this.protocolVersion);

            // Get timeout, description and isolation flags
            uint           timeout;
            IsolationFlags isoFlags;
            string         description;

            OleTxTransactionFormatter.GetTransactionAttributes(transaction,
                                                               out timeout,
                                                               out isoFlags,
                                                               out description);
            context.IsolationFlags = isoFlags;
            context.Description    = description;

            // If we can, use cached extended information
            // Note - it may be worth using outgoing contexts more than once.
            // We'll let performance profiling decide that question
            WsatExtendedInformation info;

            if (WsatExtendedInformationCache.Find(transaction, out info))
            {
                context.Expires = info.Timeout;

                // The extended info cache only contains an identifier when it's non-native
                if (!string.IsNullOrEmpty(info.Identifier))
                {
                    context.Identifier = info.Identifier;
                    nonNativeContextId = info.Identifier;
                }
            }
            else
            {
                context.Expires = timeout;
                if (context.Expires == 0)
                {
                    // If the timeout is zero, there are two possibilities:
                    // 1) This is a root transaction with an infinite timeout.
                    // 2) This is a subordinate transaction whose timeout was not flowed.
                    // We have no mechanism for distinguishing between the two cases.
                    //
                    // We could always return zero here, instead of using the local max timeout.
                    // The problem is that the 2004/08 WS-C spec does not specify the meaning
                    // of a zero expires field. While we accept zero to mean "as large as possible"
                    // it would be risky to expect others to do the same.  So we only propagate
                    // zero in the expires field if the local max timeout has been disabled.
                    //
                    // This is MB 34596: how can we flow the real timeout?
                    context.Expires = (uint)TimeoutHelper.ToMilliseconds(this.wsatConfig.MaxTimeout);
                }
            }

            if (context.Identifier == null)
            {
                context.Identifier = CoordinationContext.CreateNativeIdentifier(transactionId);
                nonNativeContextId = null;
            }

            string tokenId;

            if (!this.wsatConfig.IssuedTokensEnabled)
            {
                tokenId     = null;
                issuedToken = null;
            }
            else
            {
                CoordinationServiceSecurity.CreateIssuedToken(transactionId,
                                                              context.Identifier,
                                                              this.protocolVersion,
                                                              out issuedToken,
                                                              out tokenId);
            }

            AddressHeader refParam = new WsatRegistrationHeader(transactionId, nonNativeContextId, tokenId);

            context.RegistrationService = wsatConfig.CreateRegistrationService(refParam, this.protocolVersion);
            context.IsolationLevel      = transaction.IsolationLevel;
            context.LocalTransactionId  = transactionId;

            if (this.wsatConfig.OleTxUpgradeEnabled)
            {
                context.PropagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
            }
        }
 public void MarshalAsCoordinationContext(Transaction transaction, out CoordinationContext context, out RequestSecurityTokenResponse issuedToken)
 {
     uint num;
     IsolationFlags flags;
     string str2;
     WsatExtendedInformation information;
     string str3;
     Guid distributedIdentifier = transaction.TransactionInformation.DistributedIdentifier;
     string contextId = null;
     context = new CoordinationContext(this.protocolVersion);
     OleTxTransactionFormatter.GetTransactionAttributes(transaction, out num, out flags, out str2);
     context.IsolationFlags = flags;
     context.Description = str2;
     if (TransactionCache<Transaction, WsatExtendedInformation>.Find(transaction, out information))
     {
         context.Expires = information.Timeout;
         if (!string.IsNullOrEmpty(information.Identifier))
         {
             context.Identifier = information.Identifier;
             contextId = information.Identifier;
         }
     }
     else
     {
         context.Expires = num;
         if (context.Expires == 0)
         {
             context.Expires = (uint) TimeoutHelper.ToMilliseconds(this.wsatConfig.MaxTimeout);
         }
     }
     if (context.Identifier == null)
     {
         context.Identifier = CoordinationContext.CreateNativeIdentifier(distributedIdentifier);
         contextId = null;
     }
     if (!this.wsatConfig.IssuedTokensEnabled)
     {
         str3 = null;
         issuedToken = null;
     }
     else
     {
         CoordinationServiceSecurity.CreateIssuedToken(distributedIdentifier, context.Identifier, this.protocolVersion, out issuedToken, out str3);
     }
     AddressHeader refParam = new WsatRegistrationHeader(distributedIdentifier, contextId, str3);
     context.RegistrationService = this.wsatConfig.CreateRegistrationService(refParam, this.protocolVersion);
     context.IsolationLevel = transaction.IsolationLevel;
     context.LocalTransactionId = distributedIdentifier;
     if (this.wsatConfig.OleTxUpgradeEnabled)
     {
         context.PropagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
     }
 }