private CoordinationContext CreateCoordinationContext(WsatTransactionInfo info)
        {
            CoordinationContext coordinationContext;

            Microsoft.Transactions.Wsat.Messaging.CreateCoordinationContext cccMessage = new Microsoft.Transactions.Wsat.Messaging.CreateCoordinationContext(this.protocolVersion)
            {
                CurrentContext = info.Context,
                IssuedToken    = info.IssuedToken
            };
            try
            {
                using (new OperationContextScope(null))
                {
                    coordinationContext = this.Enlist(ref cccMessage).CoordinationContext;
                }
            }
            catch (WsatFaultException exception)
            {
                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("UnmarshalTransactionFaulted", new object[] { exception.Message }), exception));
            }
            catch (WsatSendFailureException exception2)
            {
                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Error);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionManagerCommunicationException(System.ServiceModel.SR.GetString("TMCommunicationError"), exception2));
            }
            return(coordinationContext);
        }
 private CoordinationContext CreateCoordinationContext(WsatTransactionInfo info)
 {
     CoordinationContext coordinationContext;
     Microsoft.Transactions.Wsat.Messaging.CreateCoordinationContext cccMessage = new Microsoft.Transactions.Wsat.Messaging.CreateCoordinationContext(this.protocolVersion) {
         CurrentContext = info.Context,
         IssuedToken = info.IssuedToken
     };
     try
     {
         using (new OperationContextScope(null))
         {
             coordinationContext = this.Enlist(ref cccMessage).CoordinationContext;
         }
     }
     catch (WsatFaultException exception)
     {
         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("UnmarshalTransactionFaulted", new object[] { exception.Message }), exception));
     }
     catch (WsatSendFailureException exception2)
     {
         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Error);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionManagerCommunicationException(System.ServiceModel.SR.GetString("TMCommunicationError"), exception2));
     }
     return coordinationContext;
 }
Ejemplo n.º 3
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 CreateCoordinationContext from a non-APTCA assembly and the CreateCoordinationContext constructor does an Environment.FailFast
         * // if the argument is invalid. 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)]
         */
        CoordinationContext CreateCoordinationContext(WsatTransactionInfo info)
        {
            CreateCoordinationContext cccMessage = new CreateCoordinationContext(this.protocolVersion);

            cccMessage.CurrentContext = info.Context;
            cccMessage.IssuedToken    = info.IssuedToken;

            try
            {
                // This was necessary during some portions of WCF 1.0 development
                // It is probably not needed now. However, it seems conceptually
                // solid to separate this operation from the incoming app message as
                // much as possible.  There have also been enough ServiceModel bugs in
                // this area that it does not seem wise to remove this at the moment
                // (2006/3/30, WCF 1.0 RC1 milestone)
                using (new OperationContextScope((OperationContext)null))
                {
                    return(Enlist(ref cccMessage).CoordinationContext);
                }
            }
            catch (WsatFaultException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new TransactionException(SR.GetString(SR.UnmarshalTransactionFaulted, e.Message), e));
            }
            catch (WsatSendFailureException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new TransactionManagerCommunicationException(SR.GetString(SR.TMCommunicationError), e));
            }
        }
        public Transaction UnmarshalTransaction(WsatTransactionInfo info)
        {
            if (info.Context.ProtocolVersion != this.protocolVersion)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("InvalidWsatProtocolVersion")));
            }
            if (this.wsatConfig.OleTxUpgradeEnabled)
            {
                byte[] propagationToken = info.Context.PropagationToken;
                if (propagationToken != null)
                {
                    try
                    {
                        return(OleTxTransactionInfo.UnmarshalPropagationToken(propagationToken));
                    }
                    catch (TransactionException exception)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                    }
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Information, 0xe000e, System.ServiceModel.SR.GetString("TraceCodeTxFailedToNegotiateOleTx", new object[] { info.Context.Identifier }));
                    }
                }
            }
            CoordinationContext context = info.Context;

            if (!this.wsatConfig.IsLocalRegistrationService(context.RegistrationService, this.protocolVersion))
            {
                if (!this.wsatConfig.IsProtocolServiceEnabled(this.protocolVersion))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("WsatProtocolServiceDisabled", new object[] { this.protocolVersion })));
                }
                if (!this.wsatConfig.InboundEnabled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("InboundTransactionsDisabled")));
                }
                if (this.wsatConfig.IsDisabledRegistrationService(context.RegistrationService))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("SourceTransactionsDisabled")));
                }
                context = this.CreateCoordinationContext(info);
            }
            Guid localTransactionId = context.LocalTransactionId;

            if (localTransactionId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("InvalidCoordinationContextTransactionId")));
            }
            return(OleTxTransactionInfo.UnmarshalPropagationToken(MarshalPropagationToken(ref localTransactionId, context.IsolationLevel, context.IsolationFlags, context.Description)));
        }
 public Transaction UnmarshalTransaction(WsatTransactionInfo info)
 {
     if (info.Context.ProtocolVersion != this.protocolVersion)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("InvalidWsatProtocolVersion")));
     }
     if (this.wsatConfig.OleTxUpgradeEnabled)
     {
         byte[] propagationToken = info.Context.PropagationToken;
         if (propagationToken != null)
         {
             try
             {
                 return OleTxTransactionInfo.UnmarshalPropagationToken(propagationToken);
             }
             catch (TransactionException exception)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
             }
             if (DiagnosticUtility.ShouldTraceInformation)
             {
                 TraceUtility.TraceEvent(TraceEventType.Information, 0xe000e, System.ServiceModel.SR.GetString("TraceCodeTxFailedToNegotiateOleTx", new object[] { info.Context.Identifier }));
             }
         }
     }
     CoordinationContext context = info.Context;
     if (!this.wsatConfig.IsLocalRegistrationService(context.RegistrationService, this.protocolVersion))
     {
         if (!this.wsatConfig.IsProtocolServiceEnabled(this.protocolVersion))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("WsatProtocolServiceDisabled", new object[] { this.protocolVersion })));
         }
         if (!this.wsatConfig.InboundEnabled)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("InboundTransactionsDisabled")));
         }
         if (this.wsatConfig.IsDisabledRegistrationService(context.RegistrationService))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("SourceTransactionsDisabled")));
         }
         context = this.CreateCoordinationContext(info);
     }
     Guid localTransactionId = context.LocalTransactionId;
     if (localTransactionId == Guid.Empty)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("InvalidCoordinationContextTransactionId")));
     }
     return OleTxTransactionInfo.UnmarshalPropagationToken(MarshalPropagationToken(ref localTransactionId, context.IsolationLevel, context.IsolationFlags, context.Description));
 }
Ejemplo n.º 6
0
        public Transaction UnmarshalTransaction(WsatTransactionInfo info)
        {
            if (info.Context.ProtocolVersion != this.protocolVersion)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new ArgumentException(SR.GetString(SR.InvalidWsatProtocolVersion)));
            }

            if (wsatConfig.OleTxUpgradeEnabled)
            {
                byte[] propToken = info.Context.PropagationToken;
                if (propToken != null)
                {
                    try
                    {
                        return(OleTxTransactionInfo.UnmarshalPropagationToken(propToken));
                    }
                    catch (TransactionException e)
                    {
                        DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                    }

                    // Fall back to WS-AT unmarshal
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Information,
                                                TraceCode.TxFailedToNegotiateOleTx,
                                                SR.GetString(SR.TraceCodeTxFailedToNegotiateOleTx, info.Context.Identifier));
                    }
                }
            }

            // Optimization: if the context's registration service points to our local TM, we can
            // skip the CreateCoordinationContext step
            CoordinationContext localContext = info.Context;

            if (!this.wsatConfig.IsLocalRegistrationService(localContext.RegistrationService, this.protocolVersion))
            {
                // Our WS-AT protocol service for the context's protocol version should be enabled
                if (!this.wsatConfig.IsProtocolServiceEnabled(this.protocolVersion))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new TransactionException(SR.GetString(SR.WsatProtocolServiceDisabled, this.protocolVersion)));
                }

                // We should have enabled inbound transactions
                if (!this.wsatConfig.InboundEnabled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new TransactionException(SR.GetString(SR.InboundTransactionsDisabled)));
                }

                // The sender should have enabled both WS-AT and outbound transactions
                if (this.wsatConfig.IsDisabledRegistrationService(localContext.RegistrationService))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new TransactionException(SR.GetString(SR.SourceTransactionsDisabled)));
                }

                // Ask the WS-AT protocol service to unmarshal the transaction
                localContext = CreateCoordinationContext(info);
            }

            Guid transactionId = localContext.LocalTransactionId;

            if (transactionId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new TransactionException(SR.GetString(SR.InvalidCoordinationContextTransactionId)));
            }

            byte[] propagationToken = MarshalPropagationToken(ref transactionId,
                                                              localContext.IsolationLevel,
                                                              localContext.IsolationFlags,
                                                              localContext.Description);

            return(OleTxTransactionInfo.UnmarshalPropagationToken(propagationToken));
        }
Ejemplo n.º 7
0
        public Transaction UnmarshalTransaction(WsatTransactionInfo info)
        {
            if (info.Context.ProtocolVersion != this.protocolVersion)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new ArgumentException(SR.GetString(SR.InvalidWsatProtocolVersion)));
            }

            if (wsatConfig.OleTxUpgradeEnabled)
            {
                byte[] propToken = info.Context.PropagationToken;
                if (propToken != null)
                {
                    try
                    {
                        return OleTxTransactionInfo.UnmarshalPropagationToken(propToken);
                    }
                    catch (TransactionException e)
                    {
                        DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                    }

                    // Fall back to WS-AT unmarshal
                    if (DiagnosticUtility.ShouldTraceInformation)
                        TraceUtility.TraceEvent(TraceEventType.Information,
                                                                     TraceCode.TxFailedToNegotiateOleTx,
                                                                     SR.GetString(SR.TraceCodeTxFailedToNegotiateOleTx, info.Context.Identifier));
                }
            }

            // Optimization: if the context's registration service points to our local TM, we can
            // skip the CreateCoordinationContext step
            CoordinationContext localContext = info.Context;

            if (!this.wsatConfig.IsLocalRegistrationService(localContext.RegistrationService, this.protocolVersion))
            {
                // Our WS-AT protocol service for the context's protocol version should be enabled
                if (!this.wsatConfig.IsProtocolServiceEnabled(this.protocolVersion))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new TransactionException(SR.GetString(SR.WsatProtocolServiceDisabled, this.protocolVersion)));
                }

                // We should have enabled inbound transactions
                if (!this.wsatConfig.InboundEnabled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new TransactionException(SR.GetString(SR.InboundTransactionsDisabled)));
                }

                // The sender should have enabled both WS-AT and outbound transactions
                if (this.wsatConfig.IsDisabledRegistrationService(localContext.RegistrationService))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new TransactionException(SR.GetString(SR.SourceTransactionsDisabled)));
                }

                // Ask the WS-AT protocol service to unmarshal the transaction
                localContext = CreateCoordinationContext(info);
            }

            Guid transactionId = localContext.LocalTransactionId;
            if (transactionId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new TransactionException(SR.GetString(SR.InvalidCoordinationContextTransactionId)));
            }

            byte[] propagationToken = MarshalPropagationToken(ref transactionId,
                                                              localContext.IsolationLevel,
                                                              localContext.IsolationFlags,
                                                              localContext.Description);

            return OleTxTransactionInfo.UnmarshalPropagationToken(propagationToken);
        }
Ejemplo n.º 8
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 CreateCoordinationContext from a non-APTCA assembly and the CreateCoordinationContext constructor does an Environment.FailFast 
        // if the argument is invalid. 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)]
        */
        CoordinationContext CreateCoordinationContext(WsatTransactionInfo info)
        {
            CreateCoordinationContext cccMessage = new CreateCoordinationContext(this.protocolVersion);
            cccMessage.CurrentContext = info.Context;
            cccMessage.IssuedToken = info.IssuedToken;

            try
            {
                // This was necessary during some portions of WCF 1.0 development
                // It is probably not needed now. However, it seems conceptually 
                // solid to separate this operation from the incoming app message as 
                // much as possible.  There have also been enough ServiceModel bugs in 
                // this area that it does not seem wise to remove this at the moment
                // (2006/3/30, WCF 1.0 RC1 milestone)
                using (new OperationContextScope((OperationContext)null))
                {
                    return Enlist(ref cccMessage).CoordinationContext;
                }
            }
            catch (WsatFaultException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new TransactionException(SR.GetString(SR.UnmarshalTransactionFaulted, e.Message), e));
            }
            catch (WsatSendFailureException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new TransactionManagerCommunicationException(SR.GetString(SR.TMCommunicationError), e));
            }
        }