protected override void OnSend(Message message, TimeSpan timeout)
        {
            int length;
            MessageProperties properties            = message.Properties;
            Stream            stream                = null;
            MsmqIntegrationMessageProperty property = MsmqIntegrationMessageProperty.Get(message);

            if (property == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("MsmqMessageDoesntHaveIntegrationProperty")));
            }
            if (property.Body != null)
            {
                stream = this.factory.Serialize(property);
            }
            if (stream == null)
            {
                length = 0;
            }
            else
            {
                if (stream.Length > 0x7fffffffL)
                {
                    throw TraceUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("MessageSizeMustBeInIntegerRange")), message);
                }
                length = (int)stream.Length;
            }
            using (MsmqIntegrationOutputMessage message2 = new MsmqIntegrationOutputMessage(this.factory, length, this.RemoteAddress, property))
            {
                message2.ApplyCertificateIfNeeded(this.certificateTokenProvider, this.factory.MsmqTransportSecurity.MsmqAuthenticationMode, timeout);
                if (stream != null)
                {
                    int num3;
                    stream.Position = 0L;
                    for (int i = length; i > 0; i -= num3)
                    {
                        num3 = stream.Read(message2.Body.Buffer, 0, i);
                    }
                }
                bool lockHeld = false;
                try
                {
                    Msmq.EnterXPSendLock(out lockHeld, this.factory.MsmqTransportSecurity.MsmqProtectionLevel);
                    this.msmqQueue.Send(message2, this.transactionMode);
                    MsmqDiagnostics.DatagramSent(message2.MessageId, message);
                    property.Id = MsmqMessageId.ToString(message2.MessageId.Buffer);
                }
                catch (MsmqException exception)
                {
                    if (exception.FaultSender)
                    {
                        base.Fault();
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Normalized);
                }
                finally
                {
                    if (lockHeld)
                    {
                        Msmq.LeaveXPSendLock();
                    }
                }
            }
        }
        protected override void OnSend(Message message, TimeSpan timeout)
        {
            MessageProperties properties = message.Properties;
            Stream            stream     = null;

            MsmqIntegrationMessageProperty property = MsmqIntegrationMessageProperty.Get(message);

            if (null == property)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.MsmqMessageDoesntHaveIntegrationProperty)));
            }
            if (null != property.Body)
            {
                stream = this.factory.Serialize(property);
            }

            int size;

            if (stream == null)
            {
                size = 0;
            }
            else
            {
                if (stream.Length > int.MaxValue)
                {
                    throw TraceUtility.ThrowHelperError(new ProtocolException(SR.GetString(SR.MessageSizeMustBeInIntegerRange)), message);
                }

                size = (int)stream.Length;
            }

            using (MsmqIntegrationOutputMessage msmqMessage = new MsmqIntegrationOutputMessage(this.factory, size, this.RemoteAddress, property))
            {
                msmqMessage.ApplyCertificateIfNeeded(this.certificateTokenProvider, this.factory.MsmqTransportSecurity.MsmqAuthenticationMode, timeout);

                if (stream != null)
                {
                    stream.Position = 0;
                    for (int bytesRemaining = size; bytesRemaining > 0;)
                    {
                        int bytesRead = stream.Read(msmqMessage.Body.Buffer, 0, bytesRemaining);
                        bytesRemaining -= bytesRead;
                    }
                }

                bool lockHeld = false;
                try
                {
                    Msmq.EnterXPSendLock(out lockHeld, this.factory.MsmqTransportSecurity.MsmqProtectionLevel);
                    this.msmqQueue.Send(msmqMessage, this.transactionMode);
                    MsmqDiagnostics.DatagramSent(msmqMessage.MessageId, message);
                    property.Id = MsmqMessageId.ToString(msmqMessage.MessageId.Buffer);
                }
                catch (MsmqException ex)
                {
                    if (ex.FaultSender)
                    {
                        this.Fault();
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex.Normalized);
                }
                finally
                {
                    if (lockHeld)
                    {
                        Msmq.LeaveXPSendLock();
                    }
                }
            }
        }