Пример #1
0
        internal static void VerifySender <TChannel>(MsmqChannelFactoryBase <TChannel> factory)
        {
            if (!factory.Durable && factory.ExactlyOnce)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqNoAssurancesForVolatile")));
            }
            MsmqChannelFactory <TChannel> factory2 = factory as MsmqChannelFactory <TChannel>;

            if (((factory2 != null) && factory2.UseActiveDirectory) && (factory2.QueueTransferProtocol != QueueTransferProtocol.Native))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqActiveDirectoryRequiresNativeTransfer")));
            }
            bool?useActiveDirectory = null;

            if (factory2 != null)
            {
                useActiveDirectory = new bool?(factory2.UseActiveDirectory);
            }
            VerifySecurity(factory.MsmqTransportSecurity, useActiveDirectory);
            if (null != factory.CustomDeadLetterQueue)
            {
                bool flag;
                if (DeadLetterQueue.Custom != factory.DeadLetterQueue)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqPerAppDLQRequiresCustom")));
                }
                if (!Msmq.IsPerAppDeadLetterQueueSupported)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqPerAppDLQRequiresMsmq4")));
                }
                if (!factory.ExactlyOnce)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqPerAppDLQRequiresExactlyOnce")));
                }
                string formatName = MsmqUri.NetMsmqAddressTranslator.UriToFormatName(factory.CustomDeadLetterQueue);
                if (!MsmqQueue.IsWriteable(formatName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqDLQNotWriteable")));
                }
                if (!MsmqQueue.TryGetIsTransactional(formatName, out flag) || !flag)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqTransactedDLQExpected")));
                }
            }
            if ((null == factory.CustomDeadLetterQueue) && (DeadLetterQueue.Custom == factory.DeadLetterQueue))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqCustomRequiresPerAppDLQ")));
            }
            if (MsmqAuthenticationMode.Certificate == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                EnsureSecurityTokenManagerPresent <TChannel>(factory);
            }
        }
Пример #2
0
        internal static void VerifyReceiver(MsmqReceiveParameters receiveParameters, Uri listenUri)
        {
            MsmqException exception;
            bool          flag2;

            if (!receiveParameters.Durable && receiveParameters.ExactlyOnce)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqNoAssurancesForVolatile")));
            }
            if (receiveParameters.ReceiveContextSettings.Enabled && !receiveParameters.ExactlyOnce)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqExactlyOnceNeededForReceiveContext")));
            }
            VerifySecurity(receiveParameters.TransportSecurity, null);
            string formatName = receiveParameters.AddressTranslator.UriToFormatName(listenUri);

            if (receiveParameters.ReceiveContextSettings.Enabled && formatName.Contains(";"))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqReceiveContextSubqueuesNotSupported")));
            }
            if (!MsmqQueue.IsReadable(formatName, out exception))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqQueueNotReadable"), exception));
            }
            bool flag = false;

            flag = MsmqQueue.TryGetIsTransactional(formatName, out flag2);
            try
            {
                if (!flag && (receiveParameters is MsmqTransportReceiveParameters))
                {
                    flag = MsmqQueue.TryGetIsTransactional(MsmqUri.ActiveDirectoryAddressTranslator.UriToFormatName(listenUri), out flag2);
                }
            }
            catch (MsmqException exception2)
            {
                MsmqDiagnostics.ExpectedException(exception2);
            }
            if (flag)
            {
                if (!receiveParameters.ExactlyOnce && flag2)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqNonTransactionalQueueNeeded")));
                }
                if (receiveParameters.ExactlyOnce && !flag2)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqTransactionalQueueNeeded")));
                }
            }
            if (receiveParameters.ExactlyOnce)
            {
                if (Msmq.IsAdvancedPoisonHandlingSupported)
                {
                    if (!formatName.Contains(";"))
                    {
                        if (!MsmqQueue.IsMoveable(formatName + ";retry"))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqDirectFormatNameRequiredForPoison")));
                        }
                    }
                    else if (ReceiveErrorHandling.Move == receiveParameters.ReceiveErrorHandling)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqNoMoveForSubqueues")));
                    }
                }
                else if ((ReceiveErrorHandling.Reject == receiveParameters.ReceiveErrorHandling) || (ReceiveErrorHandling.Move == receiveParameters.ReceiveErrorHandling))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqAdvancedPoisonHandlingRequired")));
                }
            }
        }
Пример #3
0
        internal static void VerifyReceiver(MsmqReceiveParameters receiveParameters, Uri listenUri)
        {
            if (!receiveParameters.Durable && receiveParameters.ExactlyOnce)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqNoAssurancesForVolatile)));
            }
            if (receiveParameters.ReceiveContextSettings.Enabled && !receiveParameters.ExactlyOnce)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqExactlyOnceNeededForReceiveContext)));
            }

            VerifySecurity(receiveParameters.TransportSecurity, null);

            string formatName = receiveParameters.AddressTranslator.UriToFormatName(listenUri);

            if (receiveParameters.ReceiveContextSettings.Enabled && formatName.Contains(";"))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqReceiveContextSubqueuesNotSupported)));
            }

            // check if can open the queue for read
            MsmqException msmqException;

            if (!MsmqQueue.IsReadable(formatName, out msmqException))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqQueueNotReadable), msmqException));
            }

            // check if the queue is transactional
            bool knownTxStatus = false;
            bool isQueueTx;

            knownTxStatus = MsmqQueue.TryGetIsTransactional(formatName, out isQueueTx);
            try
            {
                if (!knownTxStatus && (receiveParameters is MsmqTransportReceiveParameters))
                {
                    knownTxStatus = MsmqQueue.TryGetIsTransactional(MsmqUri.ActiveDirectoryAddressTranslator.UriToFormatName(listenUri), out isQueueTx);
                }
            }
            catch (MsmqException ex) // active directory lookup may cause exceptions for certain scenarios
            {
                MsmqDiagnostics.ExpectedException(ex);
            }
            if (knownTxStatus)
            {
                if (!receiveParameters.ExactlyOnce && isQueueTx)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqNonTransactionalQueueNeeded)));
                }
                if (receiveParameters.ExactlyOnce && !isQueueTx)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqTransactionalQueueNeeded)));
                }
            }

            // check poison handling settings
            if (receiveParameters.ExactlyOnce)
            {
                if (Msmq.IsAdvancedPoisonHandlingSupported) // msmq 4
                {
                    if (formatName.Contains(";"))
                    {
                        // no retry queues for subqueues
                        if (ReceiveErrorHandling.Move == receiveParameters.ReceiveErrorHandling)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqNoMoveForSubqueues)));
                        }
                    }
                    else
                    {
                        // should be able to open the retry queue for move
                        if (!MsmqQueue.IsMoveable(formatName + ";retry"))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqDirectFormatNameRequiredForPoison)));
                        }
                    }
                }
                else
                {
                    if (ReceiveErrorHandling.Reject == receiveParameters.ReceiveErrorHandling || ReceiveErrorHandling.Move == receiveParameters.ReceiveErrorHandling)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqAdvancedPoisonHandlingRequired)));
                    }
                }
            }
        }
Пример #4
0
        internal static void VerifySender <TChannel>(MsmqChannelFactoryBase <TChannel> factory)
        {
            // no assurances if messages are volatile
            if (!factory.Durable && factory.ExactlyOnce)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqNoAssurancesForVolatile)));
            }

            MsmqChannelFactory <TChannel> transportFactory = factory as MsmqChannelFactory <TChannel>;

            if (null != transportFactory && transportFactory.UseActiveDirectory && QueueTransferProtocol.Native != transportFactory.QueueTransferProtocol)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqActiveDirectoryRequiresNativeTransfer)));
            }

            bool?useActiveDirectory = null;

            if (null != transportFactory)
            {
                useActiveDirectory = transportFactory.UseActiveDirectory;
            }
            VerifySecurity(factory.MsmqTransportSecurity, useActiveDirectory);

            if (null != factory.CustomDeadLetterQueue)
            {
                if (DeadLetterQueue.Custom != factory.DeadLetterQueue)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqPerAppDLQRequiresCustom)));
                }

                if (!Msmq.IsPerAppDeadLetterQueueSupported)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqPerAppDLQRequiresMsmq4)));
                }

                if (!factory.ExactlyOnce)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqPerAppDLQRequiresExactlyOnce)));
                }

                string dlqFormatName = MsmqUri.NetMsmqAddressTranslator.UriToFormatName(factory.CustomDeadLetterQueue);

                if (!MsmqQueue.IsWriteable(dlqFormatName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqDLQNotWriteable)));
                }

                bool isQueueTx;
                if (!MsmqQueue.TryGetIsTransactional(dlqFormatName, out isQueueTx) || !isQueueTx)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqTransactedDLQExpected)));
                }
            }

            if (null == factory.CustomDeadLetterQueue && DeadLetterQueue.Custom == factory.DeadLetterQueue)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqCustomRequiresPerAppDLQ)));
            }

            // token provider needed if Certificate mode requested
            if (MsmqAuthenticationMode.Certificate == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                EnsureSecurityTokenManagerPresent <TChannel>(factory);
            }
        }