public void Rollback(Message message)
 {
     try
     {
         if (DebugTrace.Verbose)
         {
             DebugTrace.Trace(TraceLevel.Verbose, "Dispatching completion Rollback message");
             if (DebugTrace.Pii)
             {
                 DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message));
             }
         }
         RollbackMessage.ReadFrom(message, this.service.ProtocolVersion);
         this.dispatch.Rollback(message);
     }
     catch (CommunicationException exception)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
         base.OnMessageException(message, exception);
     }
     catch (Exception exception2)
     {
         DebugTrace.Trace(TraceLevel.Error, "Unhandled exception {0} dispatching completion Rollback message: {1}", exception2.GetType().Name, exception2);
         Microsoft.Transactions.Bridge.DiagnosticUtility.InvokeFinalHandler(exception2);
     }
 }
 public void Replay(Message message)
 {
     ProtocolVersionHelper.AssertProtocolVersion10(this.protocolVersion, typeof(TwoPhaseCommitCoordinatorDispatcher), "constr");
     try
     {
         if (DebugTrace.Verbose)
         {
             DebugTrace.Trace(TraceLevel.Verbose, "Dispatching 2PC Replay message");
             if (DebugTrace.Pii)
             {
                 DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message));
             }
         }
         ReplayMessage.ReadFrom(message, this.protocolVersion);
         this.dispatch.Replay(message);
     }
     catch (CommunicationException exception)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
         base.OnMessageException(message, exception);
     }
     catch (Exception exception2)
     {
         DebugTrace.Trace(TraceLevel.Error, "Unhandled exception {0} dispatching Replay message: {1}", exception2.GetType().Name, exception2);
         Microsoft.Transactions.Bridge.DiagnosticUtility.InvokeFinalHandler(exception2);
     }
 }
 private void Fault(Message message)
 {
     try
     {
         MessageFault fault = MessageFault.CreateFault(message, 0x10000);
         if (DebugTrace.Verbose)
         {
             FaultCode baseFaultCode = Library.GetBaseFaultCode(fault);
             DebugTrace.Trace(TraceLevel.Verbose, "Dispatching participant completion fault {0}", (baseFaultCode == null) ? "unknown" : baseFaultCode.Name);
             if (DebugTrace.Pii)
             {
                 DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message));
             }
         }
         this.dispatch.Fault(message, fault);
     }
     catch (CommunicationException exception)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
         base.OnMessageException(message, exception);
     }
     catch (Exception exception2)
     {
         DebugTrace.Trace(TraceLevel.Error, "Unhandled exception {0} dispatching completion fault from participant: {1}", exception2.GetType().Name, exception2);
         Microsoft.Transactions.Bridge.DiagnosticUtility.InvokeFinalHandler(exception2);
     }
 }
예제 #4
0
        public RegisterResponse EndSendRegister(IAsyncResult ar)
        {
            RegisterResponse response;

            try
            {
                Message message = base.EndSendRequest(ar, base.coordinationStrings.RegisterResponseAction);
                using (message)
                {
                    if (DebugTrace.Verbose)
                    {
                        DebugTrace.Trace(TraceLevel.Verbose, "Dispatching RegisterResponse reply");
                        if (DebugTrace.Pii)
                        {
                            DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message));
                        }
                    }
                    response = new RegisterResponse(message, base.protocolVersion);
                }
            }
            catch (CommunicationException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WsatReceiveFailureException(exception));
            }
            return(response);
        }
 public IAsyncResult BeginCreateCoordinationContext(Message message, AsyncCallback callback, object state)
 {
     if (DebugTrace.Verbose)
     {
         DebugTrace.Trace(TraceLevel.Verbose, "Dispatching CreateCoordinationContext request");
         if (DebugTrace.Pii)
         {
             DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message));
         }
     }
     Microsoft.Transactions.Wsat.Messaging.RequestAsyncResult result = new Microsoft.Transactions.Wsat.Messaging.RequestAsyncResult(message, callback, state);
     try
     {
         this.dispatch.CreateCoordinationContext(message, result);
     }
     catch (InvalidMessageException exception)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
         base.OnMessageException(result, message, exception, Faults.Version(this.service.ProtocolVersion).InvalidParameters);
     }
     catch (CommunicationException exception2)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Warning);
         base.OnMessageException(result, message, exception2, Faults.Version(this.service.ProtocolVersion).CreateContextDispatchFailed);
     }
     catch (Exception exception3)
     {
         DebugTrace.Trace(TraceLevel.Error, "Unhandled exception {0} dispatching CreateCoordinationContext message: {1}", exception3.GetType().Name, exception3);
         Microsoft.Transactions.Bridge.DiagnosticUtility.InvokeFinalHandler(exception3);
     }
     return(result);
 }
        private SecurityContextSecurityToken DeriveToken(Guid transactionId, string tokenId)
        {
            byte[]   key    = CoordinationServiceSecurity.DeriveIssuedTokenKey(transactionId, tokenId);
            DateTime utcNow = DateTime.UtcNow;

            return(new SecurityContextSecurityToken(new UniqueId(tokenId), key, utcNow, utcNow + TimeSpan.FromMinutes(5.0)));
        }
 public CreateCoordinationContext(Message message, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion) : this(protocolVersion)
 {
     if (message.IsEmpty)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
     }
     XmlDictionaryReader readerAtBodyContents = message.GetReaderAtBodyContents();
     using (readerAtBodyContents)
     {
         this.ReadFrom(readerAtBodyContents);
         try
         {
             message.ReadFromBodyContentsToEnd(readerAtBodyContents);
         }
         catch (XmlException exception)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
         }
     }
     if (this.CurrentContext != null)
     {
         try
         {
             this.IssuedToken = CoordinationServiceSecurity.GetIssuedToken(message, this.CurrentContext.Identifier, protocolVersion);
         }
         catch (XmlException exception2)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(exception2.Message, exception2));
         }
     }
 }
예제 #8
0
        private RegisterMessage CreateRegisterMessage(ref Register register)
        {
            RegisterMessage message = new RegisterMessage(base.messageVersion, ref register);

            if (register.SupportingToken != null)
            {
                CoordinationServiceSecurity.AddSupportingToken(message, register.SupportingToken);
            }
            return(message);
        }
        public static void SendCreateCoordinationContextResponse(Microsoft.Transactions.Wsat.Messaging.RequestAsyncResult result, ref CreateCoordinationContextResponse response)
        {
            Message message = new CreateCoordinationContextResponseMessage(result.MessageVersion, ref response);

            if (response.IssuedToken != null)
            {
                CoordinationServiceSecurity.AddIssuedToken(message, response.IssuedToken);
            }
            result.Finished(message);
        }
        private CreateCoordinationContextMessage CreateCreateCoordinationContextMessage(ref CreateCoordinationContext create)
        {
            CreateCoordinationContextMessage message = new CreateCoordinationContextMessage(base.messageVersion, ref create);

            if (create.IssuedToken != null)
            {
                CoordinationServiceSecurity.AddIssuedToken(message, create.IssuedToken);
            }
            return(message);
        }
예제 #11
0
        public RegisterResponse SendRegister(ref Register register)
        {
            if (DebugTrace.Verbose)
            {
                DebugTrace.Trace(TraceLevel.Verbose, "Sending Register to {0}", base.to.Uri);
            }
            Message message  = this.CreateRegisterMessage(ref register);
            Message message2 = base.SendRequest(message, base.coordinationStrings.RegisterResponseAction);

            using (message2)
            {
                if (DebugTrace.Verbose)
                {
                    DebugTrace.Trace(TraceLevel.Verbose, "Dispatching RegisterResponse reply");
                    if (DebugTrace.Pii)
                    {
                        DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message2));
                    }
                }
                return(new RegisterResponse(message2, base.protocolVersion));
            }
        }
        public CreateCoordinationContextResponse SendCreateCoordinationContext(ref CreateCoordinationContext create)
        {
            if (DebugTrace.Verbose)
            {
                DebugTrace.Trace(TraceLevel.Verbose, "Sending CreateCoordinationContext to {0}", base.to.Uri);
            }
            Message message  = this.CreateCreateCoordinationContextMessage(ref create);
            Message message2 = base.SendRequest(message, base.coordinationStrings.CreateCoordinationContextResponseAction);

            using (message2)
            {
                if (DebugTrace.Verbose)
                {
                    DebugTrace.Trace(TraceLevel.Verbose, "Dispatching CreateCoordinationContextResponse reply");
                    if (DebugTrace.Pii)
                    {
                        DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message2));
                    }
                }
                return(new CreateCoordinationContextResponse(message2, base.protocolVersion));
            }
        }
 private void TraceAccessCheckResult(bool result, MessageProperties messageProperties)
 {
     if (result)
     {
         if (DebugTrace.Info)
         {
             if (DebugTrace.Pii)
             {
                 DebugTrace.TracePii(TraceLevel.Info, "Access granted to {0} by global ACL", CoordinationServiceSecurity.GetSenderName(messageProperties));
             }
             else
             {
                 DebugTrace.Trace(TraceLevel.Info, "Access granted by global ACL");
             }
         }
     }
     else if (DebugTrace.Warning)
     {
         if (DebugTrace.Pii)
         {
             DebugTrace.TracePii(TraceLevel.Warning, "Access denied to {0} by global ACL", CoordinationServiceSecurity.GetSenderName(messageProperties));
         }
         else
         {
             DebugTrace.Trace(TraceLevel.Warning, "Access denied by global ACL");
         }
     }
 }
        private void Initialize(CoordinationServiceConfiguration config)
        {
            DebugTrace.TraceEnter(this, "Initialize");
            this.config   = config;
            this.security = new CoordinationServiceSecurity();
            if ((config.Mode == 0) || ((config.Mode & ~(CoordinationServiceMode.ProtocolService | CoordinationServiceMode.Formatter)) != 0))
            {
                DiagnosticUtility.FailFast("Invalid CoordinationServiceMode");
            }
            if ((config.Mode & CoordinationServiceMode.ProtocolService) == 0)
            {
                if (!string.IsNullOrEmpty(config.BasePath))
                {
                    DiagnosticUtility.FailFast("A base path must not be provided if protocol service mode is not enabled");
                }
                if (!string.IsNullOrEmpty(config.HostName))
                {
                    DiagnosticUtility.FailFast("A hostname must not be provided if protocol service mode is not enabled");
                }
            }
            else
            {
                if (string.IsNullOrEmpty(config.BasePath))
                {
                    DiagnosticUtility.FailFast("A base path must be provided if protocol service mode is enabled");
                }
                if (string.IsNullOrEmpty(config.HostName))
                {
                    DiagnosticUtility.FailFast("A hostname must be provided if protocol service mode is enabled");
                }
                if (config.X509Certificate == null)
                {
                    DiagnosticUtility.FailFast("No authentication mechanism was provided for the protocol service");
                }
            }
            this.globalAclAuthz = new GlobalAclOperationRequirement(config.GlobalAclWindowsIdentities, config.GlobalAclX509CertificateThumbprints, this.protocolVersion);
            if ((this.config.Mode & CoordinationServiceMode.ProtocolService) != 0)
            {
                this.httpsBaseAddressUri     = new UriBuilder(Uri.UriSchemeHttps, this.config.HostName, this.config.HttpsPort, this.config.BasePath).Uri;
                this.namedPipeBaseAddressUri = new UriBuilder(Uri.UriSchemeNetPipe, "localhost", -1, this.config.HostName + "/" + this.config.BasePath).Uri;
            }
            this.namedPipeActivationBinding = new NamedPipeBinding(this.protocolVersion);
            if (this.config.RemoteClientsEnabled)
            {
                this.windowsActivationBinding = new WindowsRequestReplyBinding(this.protocolVersion);
            }
            this.interopDatagramBinding     = new Microsoft.Transactions.Wsat.Messaging.InteropDatagramBinding(this.protocolVersion);
            this.interopRegistrationBinding = new Microsoft.Transactions.Wsat.Messaging.InteropRegistrationBinding(this.httpsBaseAddressUri, this.config.SupportingTokensEnabled, this.protocolVersion);
            this.interopActivationBinding   = new Microsoft.Transactions.Wsat.Messaging.InteropActivationBinding(this.httpsBaseAddressUri, this.protocolVersion);
            ClientCredentials item = new ClientCredentials {
                ClientCertificate  = { Certificate = this.config.X509Certificate },
                ServiceCertificate = { DefaultCertificate = this.config.X509Certificate }
            };

            if ((this.config.Mode & CoordinationServiceMode.ProtocolService) != 0)
            {
                this.interopDatagramChannelFactory = this.CreateChannelFactory <IDatagramService>(this.interopDatagramBinding);
                this.interopDatagramChannelFactory.Endpoint.Behaviors.Remove <ClientCredentials>();
                this.interopDatagramChannelFactory.Endpoint.Behaviors.Add(item);
                this.OpenChannelFactory <IDatagramService>(this.interopDatagramChannelFactory);
                this.interopRegistrationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.interopRegistrationBinding);
                this.interopRegistrationChannelFactory.Endpoint.Behaviors.Remove <ClientCredentials>();
                this.interopRegistrationChannelFactory.Endpoint.Behaviors.Add(item);
                this.OpenChannelFactory <IRequestReplyService>(this.interopRegistrationChannelFactory);
            }
            if ((config.Mode & CoordinationServiceMode.Formatter) != 0)
            {
                if (this.config.X509Certificate != null)
                {
                    this.interopActivationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.interopActivationBinding);
                    this.interopActivationChannelFactory.Endpoint.Behaviors.Remove <ClientCredentials>();
                    this.interopActivationChannelFactory.Endpoint.Behaviors.Add(item);
                    this.OpenChannelFactory <IRequestReplyService>(this.interopActivationChannelFactory);
                }
                this.namedPipeActivationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.namedPipeActivationBinding);
                this.OpenChannelFactory <IRequestReplyService>(this.namedPipeActivationChannelFactory);
                if (this.config.RemoteClientsEnabled)
                {
                    this.windowsActivationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.windowsActivationBinding);
                    this.OpenChannelFactory <IRequestReplyService>(this.windowsActivationChannelFactory);
                }
            }
            this.requestReplyChannelCache = new ChannelMruCache <IRequestReplyService>();
            if ((this.config.Mode & CoordinationServiceMode.ProtocolService) != 0)
            {
                this.datagramChannelCache = new ChannelMruCache <IDatagramService>();
            }
            DebugTrace.TraceLeave(this, "Initialize");
        }