Пример #1
0
 private static void EnsureSecurityTokenManagerPresent <TChannel>(MsmqChannelFactoryBase <TChannel> factory)
 {
     if (factory.SecurityTokenManager == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqTokenProviderNeededForCertificates")));
     }
 }
Пример #2
0
 static void EnsureSecurityTokenManagerPresent <TChannel>(MsmqChannelFactoryBase <TChannel> factory)
 {
     if (null == factory.SecurityTokenManager)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqTokenProviderNeededForCertificates)));
     }
 }
Пример #3
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);
            }
        }
Пример #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);
            }
        }
Пример #5
0
        protected MsmqOutputMessage(MsmqChannelFactoryBase <TChannel> factory, int bodySize, EndpointAddress remoteAddress, int additionalPropertyCount) : base(15 + additionalPropertyCount)
        {
            this.body      = new NativeMsmqMessage.BufferProperty(this, 9, bodySize);
            this.messageId = new NativeMsmqMessage.BufferProperty(this, 2, 20);
            this.EnsureBodyTypeProperty(0x1011);
            this.EnsureJournalProperty(2, factory.UseSourceJournal);
            this.delivery = new NativeMsmqMessage.ByteProperty(this, 5);
            if (factory.Durable)
            {
                this.delivery.Value = 1;
            }
            else
            {
                this.delivery.Value = 0;
            }
            if (factory.TimeToLive != TimeSpan.MaxValue)
            {
                int num = MsmqDuration.FromTimeSpan(factory.TimeToLive);
                this.EnsureTimeToReachQueueProperty(num);
                this.timeToBeReceived = new NativeMsmqMessage.IntProperty(this, 14, num);
            }
            switch (factory.DeadLetterQueue)
            {
            case DeadLetterQueue.None:
                this.EnsureJournalProperty(1, false);
                break;

            case DeadLetterQueue.System:
                this.EnsureJournalProperty(1, true);
                break;

            case DeadLetterQueue.Custom:
                this.EnsureJournalProperty(1, true);
                this.EnsureDeadLetterQueueProperty(factory.DeadLetterQueuePathName);
                break;
            }
            if (MsmqAuthenticationMode.WindowsDomain == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                this.EnsureSenderIdTypeProperty(1);
                this.authLevel     = new NativeMsmqMessage.IntProperty(this, 0x18, 1);
                this.hashAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1a, MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));
                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel           = new NativeMsmqMessage.IntProperty(this, 0x17, 3);
                    this.encryptionAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1b, MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }
            }
            else if (MsmqAuthenticationMode.Certificate == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                this.authLevel     = new NativeMsmqMessage.IntProperty(this, 0x18, 1);
                this.hashAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1a, MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));
                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel           = new NativeMsmqMessage.IntProperty(this, 0x17, 3);
                    this.encryptionAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1b, MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }
                this.EnsureSenderIdTypeProperty(0);
                this.senderCert = new NativeMsmqMessage.BufferProperty(this, 0x1c);
            }
            else
            {
                this.authLevel = new NativeMsmqMessage.IntProperty(this, 0x18, 0);
                this.EnsureSenderIdTypeProperty(0);
            }
            this.trace = new NativeMsmqMessage.ByteProperty(this, 0x29, factory.UseMsmqTracing ? ((byte)1) : ((byte)0));
        }
Пример #6
0
 public MsmqOutputMessage(MsmqChannelFactoryBase <TChannel> factory, int bodySize, EndpointAddress remoteAddress) : this(factory, bodySize, remoteAddress, 0)
 {
 }
Пример #7
0
        protected MsmqOutputMessage(MsmqChannelFactoryBase <TChannel> factory, int bodySize, EndpointAddress remoteAddress, int additionalPropertyCount)
            : base(15 + additionalPropertyCount)
        {
            this.body      = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_BODY, bodySize);
            this.messageId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_MSGID, UnsafeNativeMethods.PROPID_M_MSGID_SIZE);

            EnsureBodyTypeProperty(UnsafeNativeMethods.VT_VECTOR | UnsafeNativeMethods.VT_UI1);
            EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_JOURNAL, factory.UseSourceJournal);

            this.delivery = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_DELIVERY);
            if (factory.Durable)
            {
                this.delivery.Value = (byte)UnsafeNativeMethods.MQMSG_DELIVERY_RECOVERABLE;
            }
            else
            {
                this.delivery.Value = (byte)UnsafeNativeMethods.MQMSG_DELIVERY_EXPRESS;
            }

            if (factory.TimeToLive != TimeSpan.MaxValue)
            {
                int totalSeconds = MsmqDuration.FromTimeSpan(factory.TimeToLive);

                EnsureTimeToReachQueueProperty(totalSeconds);

                this.timeToBeReceived = new IntProperty(this,
                                                        UnsafeNativeMethods.PROPID_M_TIME_TO_BE_RECEIVED, totalSeconds);
            }

            switch (factory.DeadLetterQueue)
            {
            case DeadLetterQueue.None:
                EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, false);
                break;

            case DeadLetterQueue.System:
                EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, true);
                break;

            case DeadLetterQueue.Custom:
                EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, true);
                EnsureDeadLetterQueueProperty(factory.DeadLetterQueuePathName);
                break;
            }

            if (MsmqAuthenticationMode.WindowsDomain == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_SID);

                this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL,
                                                 UnsafeNativeMethods.MQMSG_AUTH_LEVEL_ALWAYS);

                this.hashAlgorithm = new IntProperty(
                    this,
                    UnsafeNativeMethods.PROPID_M_HASH_ALG,
                    MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));

                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL,
                                                     UnsafeNativeMethods.MQMSG_PRIV_LEVEL_BODY_ENHANCED);

                    this.encryptionAlgorithm = new IntProperty(
                        this,
                        UnsafeNativeMethods.PROPID_M_ENCRYPTION_ALG,
                        MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }
            }
            else if (MsmqAuthenticationMode.Certificate == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL,
                                                 UnsafeNativeMethods.MQMSG_AUTH_LEVEL_ALWAYS);

                this.hashAlgorithm = new IntProperty(
                    this,
                    UnsafeNativeMethods.PROPID_M_HASH_ALG,
                    MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));

                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL,
                                                     UnsafeNativeMethods.MQMSG_PRIV_LEVEL_BODY_ENHANCED);

                    this.encryptionAlgorithm = new IntProperty(
                        this,
                        UnsafeNativeMethods.PROPID_M_ENCRYPTION_ALG,
                        MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }

                EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_NONE);
                this.senderCert = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_SENDER_CERT);
            }
            else
            {
                this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL,
                                                 UnsafeNativeMethods.MQMSG_AUTH_LEVEL_NONE);

                EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_NONE);
            }

            this.trace = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_TRACE, (byte)(factory.UseMsmqTracing ?
                                                                                           UnsafeNativeMethods.MQMSG_SEND_ROUTE_TO_REPORT_QUEUE : UnsafeNativeMethods.MQMSG_TRACE_NONE));
        }