public static CoordinationContext ReadFrom(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
        {
            CoordinationContext that = new CoordinationContext(protocolVersion);

            ReadFrom(that, reader, localName, ns, protocolVersion);
            return(that);
        }
 // 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 call into CoordinationStrings.Version(..), which is defined in a non-APTCA assembly and 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)]
 */
 public WsatTransactionHeader(CoordinationContext context, ProtocolVersion protocolVersion)
 {
     this.context = context;
     CoordinationStrings coordinationStrings = CoordinationStrings.Version(protocolVersion);                        
     this.wsatHeaderElement = coordinationStrings.CoordinationContext;
     this.wsatNamespace = coordinationStrings.Namespace;
 }
        // 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 call into CoordinationContext and CoordinationStrings, which are defined in a non-APTCA assembly. Also, CoordinationStrings.Version(..) 
        // 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)]
        */
        public static CoordinationContext GetCoordinationContext(Message message, ProtocolVersion protocolVersion)
        {
            CoordinationStrings coordinationStrings = CoordinationStrings.Version(protocolVersion);
            string locWsatHeaderElement = coordinationStrings.CoordinationContext;
            string locWsatNamespace = coordinationStrings.Namespace;
            
            int index;
            try
            {
                index = message.Headers.FindHeader(locWsatHeaderElement, locWsatNamespace);
            }
            catch (MessageHeaderException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                return null;
            }
            if (index < 0)
                return null;

            CoordinationContext context;
            XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index);
            using (reader)
            {
                context = GetCoordinationContext(reader, protocolVersion);
            }

            MessageHeaderInfo header = message.Headers[index];
            if (!message.Headers.UnderstoodHeaders.Contains(header))
            {
                message.Headers.UnderstoodHeaders.Add(header);
            }

            return context;
        }
 public static CoordinationContext GetCoordinationContext(Message message, ProtocolVersion protocolVersion)
 {
     int num;
     CoordinationContext context;
     CoordinationStrings strings = CoordinationStrings.Version(protocolVersion);
     string coordinationContext = strings.CoordinationContext;
     string ns = strings.Namespace;
     try
     {
         num = message.Headers.FindHeader(coordinationContext, ns);
     }
     catch (MessageHeaderException exception)
     {
         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
         return null;
     }
     if (num < 0)
     {
         return null;
     }
     XmlDictionaryReader readerAtHeader = message.Headers.GetReaderAtHeader(num);
     using (readerAtHeader)
     {
         context = GetCoordinationContext(readerAtHeader, protocolVersion);
     }
     MessageHeaderInfo headerInfo = message.Headers[num];
     if (!message.Headers.UnderstoodHeaders.Contains(headerInfo))
     {
         message.Headers.UnderstoodHeaders.Add(headerInfo);
     }
     return context;
 }
 public RegisterCoordinatorRecordSchema10(CoordinationContext context, ControlProtocol protocol, EndpointAddress coordinatorService) : base(context, protocol)
 {
     base.schemaId = "http://schemas.microsoft.com/2006/08/ServiceModel/RegisterCoordinatorTraceRecord";
     if (coordinatorService != null)
     {
         this.coordinatorService = EndpointAddressAugust2004.FromEndpointAddress(coordinatorService);
     }
 }
 public RegistrationCoordinatorResponseInvalidMetadataSchema11(CoordinationContext context, ControlProtocol protocol, EndpointAddress coordinatorService) : base(context, protocol)
 {
     base.schemaId = "http://schemas.microsoft.com/2006/08/ServiceModel/RegistrationCoordinatorResponseInvalidMetadata11TraceRecord";
     if (coordinatorService != null)
     {
         this.coordinatorService = EndpointAddress10.FromEndpointAddress(coordinatorService);
     }
 }
 public static void Trace(Guid enlistmentId, CoordinationContext context)
 {
     CoordinationContextRecordSchema extendedData = new CoordinationContextRecordSchema(context);
     if (DiagnosticUtility.ShouldTraceInformation)
     {
         TxTraceUtility.Trace(TraceEventType.Information, 0xb000b, Microsoft.Transactions.SR.GetString("EnlistTransaction"), extendedData, null, enlistmentId, null);
     }
 }
 public WsatTransactionInfo(WsatProxy wsatProxy, 
                            CoordinationContext context,
                            RequestSecurityTokenResponse issuedToken)
 {
     this.wsatProxy = wsatProxy;
     this.context = context;
     this.issuedToken = issuedToken;
 }
 public CoordinatorEnlistment(ProtocolState state, TransactionContextManager contextManager, CoordinationContext context, RequestSecurityTokenResponse rstr) : base(state)
 {
     base.ourContextManager = contextManager;
     this.superiorContext = context;
     this.superiorRstr = rstr;
     this.ConfigureEnlistment(context);
     base.stateMachine = new CoordinatorStateMachine(this);
     base.stateMachine.ChangeState(state.States.CoordinatorInitializing);
 }
 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);
     }
 }
        private void ReadFrom(XmlDictionaryReader reader)
        {
            try
            {
                reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContext, this.coordinationXmlDictionaryStrings.Namespace);
                if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.Expires, this.coordinationXmlDictionaryStrings.Namespace))
                {
                    int num = reader.ReadElementContentAsInt();
                    if (num < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
                    }
                    this.expiration     = (uint)num;
                    this.expiresPresent = true;
                }
                if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace))
                {
                    this.CurrentContext = CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion);
                }
                reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.CoordinationType, this.coordinationXmlDictionaryStrings.Namespace);
                if (reader.ReadElementContentAsString().Trim() != this.atomicTransactionStrings.Namespace)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
                }
                if (!reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
                {
                    goto Label_016B;
                }
                this.IsolationLevel = (System.Transactions.IsolationLevel)reader.ReadElementContentAsInt();
                if (((this.IsolationLevel >= System.Transactions.IsolationLevel.Serializable) && (this.IsolationLevel <= System.Transactions.IsolationLevel.Unspecified)) && (this.IsolationLevel != System.Transactions.IsolationLevel.Snapshot))
                {
                    goto Label_016B;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
Label_0165:
                reader.Skip();
Label_016B:
                if (reader.IsStartElement())
                {
                    goto Label_0165;
                }
                reader.ReadEndElement();
            }
            catch (XmlException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
            }
            catch (InvalidCoordinationContextException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2));
            }
        }
 public CreateCoordinationContext(Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     this.expiration      = 0;
     this.expiresPresent  = false;
     this.CurrentContext  = null;
     this.IssuedToken     = null;
     this.IsolationLevel  = System.Transactions.IsolationLevel.Serializable;
     this.protocolVersion = protocolVersion;
     this.coordinationXmlDictionaryStrings      = CoordinationXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionXmlDictionaryStrings = AtomicTransactionXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionStrings = AtomicTransactionStrings.Version(protocolVersion);
     this.coordinationStrings      = CoordinationStrings.Version(protocolVersion);
 }
 private void ConfigureEnlistment(CoordinationContext context)
 {
     Enlistment enlistment = new Enlistment();
     string identifier = context.Identifier;
     if (identifier == null)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.FailFast("Need transactionId to create enlistment");
     }
     enlistment.RemoteTransactionId = identifier;
     enlistment.LocalTransactionId = Ports.GetGuidFromTransactionId(identifier);
     enlistment.ProtocolProviderContext = this;
     base.enlistment = enlistment;
 }
 public CreateCoordinationContext(Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     this.expiration = 0;
     this.expiresPresent = false;
     this.CurrentContext = null;
     this.IssuedToken = null;
     this.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
     this.protocolVersion = protocolVersion;
     this.coordinationXmlDictionaryStrings = CoordinationXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionXmlDictionaryStrings = AtomicTransactionXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionStrings = AtomicTransactionStrings.Version(protocolVersion);
     this.coordinationStrings = CoordinationStrings.Version(protocolVersion);
 }
        public static RegisterCoordinatorRecordSchema Instance(CoordinationContext context, ControlProtocol protocol, EndpointAddress coordinatorService, ProtocolVersion protocolVersion)
        {
            ProtocolVersionHelper.AssertProtocolVersion(protocolVersion, typeof(RegisterCoordinatorRecordSchema), "Instance");
            switch (protocolVersion)
            {
                case ProtocolVersion.Version10:
                    return new RegisterCoordinatorRecordSchema10(context, protocol, coordinatorService);

                case ProtocolVersion.Version11:
                    return new RegisterCoordinatorRecordSchema11(context, protocol, coordinatorService);
            }
            return null;
        }
 public static CoordinationContext GetCoordinationContext(XmlDictionaryReader reader, ProtocolVersion protocolVersion)
 {
     CoordinationContext context;
     CoordinationXmlDictionaryStrings strings = CoordinationXmlDictionaryStrings.Version(protocolVersion);
     try
     {
         context = CoordinationContext.ReadFrom(reader, strings.CoordinationContext, strings.Namespace, protocolVersion);
     }
     catch (InvalidCoordinationContextException exception)
     {
         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(System.ServiceModel.SR.GetString("WsatHeaderCorrupt"), exception));
     }
     return context;
 }
        public static void CreateIssuedToken(Guid transactionId, string coordinationContextId, ProtocolVersion protocolVersion, out RequestSecurityTokenResponse issuedToken, out string sctId)
        {
            sctId = CoordinationContext.CreateNativeIdentifier(Guid.NewGuid());
            byte[]   key    = DeriveIssuedTokenKey(transactionId, sctId);
            DateTime utcNow = DateTime.UtcNow;
            SecurityContextSecurityToken token            = new SecurityContextSecurityToken(new UniqueId(sctId), key, utcNow, utcNow + TimeSpan.FromDays(36500.0));
            BinarySecretSecurityToken    token2           = new BinarySecretSecurityToken(key);
            SecurityStandardsManager     standardsManager = CreateStandardsManager(protocolVersion);
            RequestSecurityTokenResponse response         = new RequestSecurityTokenResponse(standardsManager)
            {
                TokenType = standardsManager.SecureConversationDriver.TokenTypeUri,
                RequestedUnattachedReference = SecurityContextSecurityTokenParameters.CreateKeyIdentifierClause(token, SecurityTokenReferenceStyle.External),
                RequestedAttachedReference   = SecurityContextSecurityTokenParameters.CreateKeyIdentifierClause(token, SecurityTokenReferenceStyle.Internal),
                RequestedSecurityToken       = token,
                RequestedProofToken          = token2
            };
            DataContractSerializer serializer = IdentifierElementSerializer(protocolVersion);

            ProtocolVersionHelper.AssertProtocolVersion(protocolVersion, typeof(CoordinationServiceSecurity), "CreateIssuedToken");
            switch (protocolVersion)
            {
            case ProtocolVersion.Version10:
                response.SetAppliesTo <IdentifierElement10>(new IdentifierElement10(coordinationContextId), serializer);
                break;

            case ProtocolVersion.Version11:
                response.SetAppliesTo <IdentifierElement11>(new IdentifierElement11(coordinationContextId), serializer);
                break;
            }
            response.MakeReadOnly();
            if (DebugTrace.Verbose)
            {
                DebugTrace.Trace(TraceLevel.Verbose, "Created issued token with id {0} for transaction {1}", sctId, transactionId);
            }
            issuedToken = response;
        }
 private static void ReadFrom(CoordinationContext that, XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     try
     {
         Uri uri;
         CoordinationXmlDictionaryStrings strings  = CoordinationXmlDictionaryStrings.Version(protocolVersion);
         AtomicTransactionStrings         strings2 = AtomicTransactionStrings.Version(protocolVersion);
         reader.ReadFullStartElement(localName, strings.Namespace);
         reader.MoveToStartElement(strings.Identifier, strings.Namespace);
         that.unknownIdentifierAttributes = ReadOtherAttributes(reader, strings.Namespace);
         that.contextId = reader.ReadElementContentAsString().Trim();
         if ((that.contextId.Length == 0) || (that.contextId.Length > 0x100))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (!Uri.TryCreate(that.contextId, UriKind.Absolute, out uri))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (reader.IsStartElement(strings.Expires, strings.Namespace))
         {
             that.unknownExpiresAttributes = ReadOtherAttributes(reader, strings.Namespace);
             int num = reader.ReadElementContentAsInt();
             if (num < 0)
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
             that.expiration     = (uint)num;
             that.expiresPresent = true;
         }
         reader.MoveToStartElement(strings.CoordinationType, strings.Namespace);
         if (reader.ReadElementContentAsString().Trim() != strings2.Namespace)
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         that.registrationRef = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(protocolVersion), reader, strings.RegistrationService, strings.Namespace);
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoLevel = (System.Transactions.IsolationLevel)reader.ReadElementContentAsInt();
             if (((that.IsolationLevel < System.Transactions.IsolationLevel.Serializable) || (that.IsolationLevel > System.Transactions.IsolationLevel.Unspecified)) || (that.IsolationLevel == System.Transactions.IsolationLevel.Snapshot))
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationFlags, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoFlags = (System.ServiceModel.Transactions.IsolationFlags)reader.ReadElementContentAsInt();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Description, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.description = reader.ReadElementContentAsString().Trim();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.localTxId = reader.ReadElementContentAsGuid();
         }
         if (OleTxTransactionHeader.IsStartPropagationTokenElement(reader))
         {
             that.propToken = OleTxTransactionHeader.ReadPropagationTokenElement(reader);
         }
         if (reader.IsStartElement())
         {
             XmlDocument document = new XmlDocument();
             that.unknownData = new List <System.Xml.XmlNode>(5);
             while (reader.IsStartElement())
             {
                 System.Xml.XmlNode item = document.ReadNode(reader);
                 that.unknownData.Add(item);
             }
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"), exception));
     }
 }
 public TransactionContext(Microsoft.Transactions.Wsat.Messaging.CoordinationContext context, RequestSecurityTokenResponse issuedToken)
 {
     this.context = context;
     this.issuedToken = issuedToken;
 }
 public static void Trace(Guid enlistmentId, CoordinationContext context, ControlProtocol protocol, Exception e)
 {
     RegistrationCoordinatorFailedSchema extendedData = new RegistrationCoordinatorFailedSchema(context, protocol);
     TxTraceUtility.Trace(TraceEventType.Warning, 0xb0007, Microsoft.Transactions.SR.GetString("RegistrationCoordinatorFailed"), extendedData, null, enlistmentId, null);
 }
 public static void Trace(Guid enlistmentId, CoordinationContext context, ControlProtocol protocol, EndpointAddress coordinatorService, ProtocolVersion protocolVersion)
 {
     RegisterCoordinatorRecordSchema extendedData = RegisterCoordinatorRecordSchema.Instance(context, protocol, coordinatorService, protocolVersion);
     TxTraceUtility.Trace(TraceEventType.Information, GetCode(protocolVersion), Microsoft.Transactions.SR.GetString("RegisterCoordinator"), extendedData, null, enlistmentId, null);
 }
 private static void ReadFrom(CoordinationContext that, XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     try
     {
         Uri uri;
         CoordinationXmlDictionaryStrings strings = CoordinationXmlDictionaryStrings.Version(protocolVersion);
         AtomicTransactionStrings strings2 = AtomicTransactionStrings.Version(protocolVersion);
         reader.ReadFullStartElement(localName, strings.Namespace);
         reader.MoveToStartElement(strings.Identifier, strings.Namespace);
         that.unknownIdentifierAttributes = ReadOtherAttributes(reader, strings.Namespace);
         that.contextId = reader.ReadElementContentAsString().Trim();
         if ((that.contextId.Length == 0) || (that.contextId.Length > 0x100))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (!Uri.TryCreate(that.contextId, UriKind.Absolute, out uri))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (reader.IsStartElement(strings.Expires, strings.Namespace))
         {
             that.unknownExpiresAttributes = ReadOtherAttributes(reader, strings.Namespace);
             int num = reader.ReadElementContentAsInt();
             if (num < 0)
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
             that.expiration = (uint) num;
             that.expiresPresent = true;
         }
         reader.MoveToStartElement(strings.CoordinationType, strings.Namespace);
         if (reader.ReadElementContentAsString().Trim() != strings2.Namespace)
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         that.registrationRef = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(protocolVersion), reader, strings.RegistrationService, strings.Namespace);
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoLevel = (System.Transactions.IsolationLevel) reader.ReadElementContentAsInt();
             if (((that.IsolationLevel < System.Transactions.IsolationLevel.Serializable) || (that.IsolationLevel > System.Transactions.IsolationLevel.Unspecified)) || (that.IsolationLevel == System.Transactions.IsolationLevel.Snapshot))
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationFlags, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoFlags = (System.ServiceModel.Transactions.IsolationFlags) reader.ReadElementContentAsInt();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Description, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.description = reader.ReadElementContentAsString().Trim();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.localTxId = reader.ReadElementContentAsGuid();
         }
         if (OleTxTransactionHeader.IsStartPropagationTokenElement(reader))
         {
             that.propToken = OleTxTransactionHeader.ReadPropagationTokenElement(reader);
         }
         if (reader.IsStartElement())
         {
             XmlDocument document = new XmlDocument();
             that.unknownData = new List<System.Xml.XmlNode>(5);
             while (reader.IsStartElement())
             {
                 System.Xml.XmlNode item = document.ReadNode(reader);
                 that.unknownData.Add(item);
             }
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"), exception));
     }
 }
 public static CoordinationContext ReadFrom(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     CoordinationContext that = new CoordinationContext(protocolVersion);
     ReadFrom(that, reader, localName, ns, protocolVersion);
     return that;
 }
 public static void Trace(Guid enlistmentId, CoordinationContext context, ControlProtocol protocol, EndpointAddress coordinatorService, Exception e, ProtocolVersion protocolVersion)
 {
     RegistrationCoordinatorResponseInvalidMetadataSchema extendedData = RegistrationCoordinatorResponseInvalidMetadataSchema.Instance(context, protocol, coordinatorService, protocolVersion);
     TxTraceUtility.Trace(TraceEventType.Warning, GetCode(protocolVersion), Microsoft.Transactions.SR.GetString("RegistrationCoordinatorResponseInvalidMetadata"), extendedData, e, enlistmentId, null);
 }
예제 #25
0
 public TransactionContext(Microsoft.Transactions.Wsat.Messaging.CoordinationContext context, RequestSecurityTokenResponse issuedToken)
 {
     this.context     = context;
     this.issuedToken = issuedToken;
 }
 //=======================================================================================
 public WsatTransactionInfo CreateTransactionInfo(CoordinationContext context,
                                                  RequestSecurityTokenResponse issuedToken)
 {
     return new WsatTransactionInfo(this.wsatProxy, context, issuedToken);
 }
 public RegistrationCoordinatorFaultedSchema(CoordinationContext context, ControlProtocol protocol, MessageFault fault)
 {
     this.context = context;
     this.protocol = protocol;
     this.fault = fault;
 }
 protected RegistrationCoordinatorResponseInvalidMetadataSchema(CoordinationContext context, ControlProtocol protocol)
 {
     this.context = context;
     this.protocol = protocol;
 }
 public CoordinationContextRecordSchema(CoordinationContext context)
 {
     this.context = context;
 }
 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);
 }
        //=======================================================================================
        // 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);
            }
        }
 protected RegisterCoordinatorRecordSchema(CoordinationContext context, ControlProtocol protocol)
 {
     this.context = context;
     this.protocol = protocol;
 }
 public static void WriteElement(XmlDictionaryWriter writer, CoordinationContext context, ProtocolVersion protocolVersion)
 {
     CoordinationXmlDictionaryStrings strings = CoordinationXmlDictionaryStrings.Version(protocolVersion);
     context.WriteTo(writer, strings.CoordinationContext, strings.Namespace);
 }
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContext, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.Expires, this.coordinationXmlDictionaryStrings.Namespace))
         {
             int num = reader.ReadElementContentAsInt();
             if (num < 0)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
             }
             this.expiration = (uint) num;
             this.expiresPresent = true;
         }
         if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace))
         {
             this.CurrentContext = CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion);
         }
         reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.CoordinationType, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.ReadElementContentAsString().Trim() != this.atomicTransactionStrings.Namespace)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
         }
         if (!reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             goto Label_016B;
         }
         this.IsolationLevel = (System.Transactions.IsolationLevel) reader.ReadElementContentAsInt();
         if (((this.IsolationLevel >= System.Transactions.IsolationLevel.Serializable) && (this.IsolationLevel <= System.Transactions.IsolationLevel.Unspecified)) && (this.IsolationLevel != System.Transactions.IsolationLevel.Snapshot))
         {
             goto Label_016B;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
     Label_0165:
         reader.Skip();
     Label_016B:
         if (reader.IsStartElement())
         {
             goto Label_0165;
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
     catch (InvalidCoordinationContextException exception2)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2));
     }
 }