Exemplo n.º 1
0
        MtomBufferedMessageWriter TakeBufferedWriter()
        {
            if (bufferedWriterPool == null)
            {
                lock (thisLock)
                {
                    if (bufferedWriterPool == null)
                    {
                        bufferedWriterPool = new SynchronizedPool <MtomBufferedMessageWriter>(maxWritePoolSize);
                    }
                }
            }

            MtomBufferedMessageWriter messageWriter = bufferedWriterPool.Take();

            if (messageWriter == null)
            {
                messageWriter = new MtomBufferedMessageWriter(this);
                if (TD.WritePoolMissIsEnabled())
                {
                    TD.WritePoolMiss(messageWriter.GetType().Name);
                }
            }
            return(messageWriter);
        }
Exemplo n.º 2
0
        private ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset, string startInfo, string boundary, string startUri, bool writeMessageHeaders)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            if (bufferManager == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
            }
            if (maxMessageSize < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize", maxMessageSize, System.ServiceModel.SR.GetString("ValueMustBeNonNegative")));
            }
            if ((messageOffset < 0) || (messageOffset > maxMessageSize))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset, System.ServiceModel.SR.GetString("ValueMustBeInRange", new object[] { 0, maxMessageSize })));
            }
            base.ThrowIfMismatchedMessageVersion(message);
            message.Properties.Encoder = this;
            MtomBufferedMessageWriter messageWriter = this.TakeBufferedWriter();

            messageWriter.StartInfo           = startInfo;
            messageWriter.Boundary            = boundary;
            messageWriter.StartUri            = startUri;
            messageWriter.WriteMessageHeaders = writeMessageHeaders;
            messageWriter.MaxSizeInBytes      = maxMessageSize;
            ArraySegment <byte> segment = messageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);

            this.ReturnMessageWriter(messageWriter);
            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                string contentType = null;
                if (boundary != null)
                {
                    contentType = this.FormatContentType(boundary, startInfo ?? this.GenerateStartInfoString());
                }
                XmlDictionaryReader reader = XmlDictionaryReader.CreateMtomReader(segment.Array, segment.Offset, segment.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, XmlDictionaryReaderQuotas.Max, 0x7fffffff, null);
                MessageLogger.LogMessage(ref message, reader, MessageLoggingSource.TransportSend);
            }
            return(segment);
        }
Exemplo n.º 3
0
        private MtomBufferedMessageWriter TakeBufferedWriter()
        {
            if (this.bufferedWriterPool == null)
            {
                lock (this.thisLock)
                {
                    if (this.bufferedWriterPool == null)
                    {
                        this.bufferedWriterPool = new SynchronizedPool <MtomBufferedMessageWriter>(this.maxWritePoolSize);
                    }
                }
            }
            MtomBufferedMessageWriter writer = this.bufferedWriterPool.Take();

            if (writer == null)
            {
                writer = new MtomBufferedMessageWriter(this);
            }
            return(writer);
        }
Exemplo n.º 4
0
 void ReturnMessageWriter(MtomBufferedMessageWriter messageWriter)
 {
     bufferedWriterPool.Return(messageWriter);
 }
Exemplo n.º 5
0
        ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset, string startInfo, string boundary, string startUri, bool writeMessageHeaders)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            if (bufferManager == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
            }
            if (maxMessageSize < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize", maxMessageSize,
                                                                                                          SR.GetString(SR.ValueMustBeNonNegative)));
            }
            if (messageOffset < 0 || messageOffset > maxMessageSize)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset,
                                                                                                          SR.GetString(SR.ValueMustBeInRange, 0, maxMessageSize)));
            }
            ThrowIfMismatchedMessageVersion(message);

            EventTraceActivity eventTraceActivity = null;

            if (TD.MtomMessageEncodingStartIsEnabled())
            {
                eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                TD.MtomMessageEncodingStart(eventTraceActivity);
            }

            message.Properties.Encoder = this;

            MtomBufferedMessageWriter messageWriter = TakeBufferedWriter();

            messageWriter.StartInfo           = startInfo;
            messageWriter.Boundary            = boundary;
            messageWriter.StartUri            = startUri;
            messageWriter.WriteMessageHeaders = writeMessageHeaders;
            messageWriter.MaxSizeInBytes      = maxMessageSize;
            ArraySegment <byte> messageData = messageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);

            ReturnMessageWriter(messageWriter);

            if (TD.MessageWrittenByEncoderIsEnabled() && messageData != null)
            {
                TD.MessageWrittenByEncoder(
                    eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message),
                    messageData.Count,
                    this);
            }

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                string contentType = null;
                if (boundary != null)
                {
                    contentType = FormatContentType(boundary, startInfo ?? GenerateStartInfoString());
                }

                XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateMtomReader(messageData.Array, messageData.Offset, messageData.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, XmlDictionaryReaderQuotas.Max, int.MaxValue, null);
                MessageLogger.LogMessage(ref message, xmlDictionaryReader, MessageLoggingSource.TransportSend);
            }

            return(messageData);
        }
Exemplo n.º 6
0
 private void ReturnMessageWriter(MtomBufferedMessageWriter messageWriter)
 {
     this.bufferedWriterPool.Return(messageWriter);
 }
Exemplo n.º 7
0
        private ArraySegment <byte> WriteMessageInternal(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset, string startInfo, string boundary, string startUri, bool writeMessageHeaders)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
            }
            if (bufferManager == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(bufferManager));
            }
            if (maxMessageSize < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(maxMessageSize), maxMessageSize,
                                                                                                          SR.ValueMustBeNonNegative));
            }
            if (messageOffset < 0 || messageOffset > maxMessageSize)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(messageOffset), messageOffset,
                                                                                                          SR.Format(SR.ValueMustBeInRange, 0, maxMessageSize)));
            }
            ThrowIfMismatchedMessageVersion(message);

            // EventTraceActivity eventTraceActivity = null;
            // if (WcfEventSource.Instance.MtomMessageEncodingStartIsEnabled())
            // {
            //     eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
            //     WcfEventSource.Instance.MtomMessageEncodingStart(eventTraceActivity);
            // }

            message.Properties.Encoder = this;

            MtomBufferedMessageWriter messageWriter = _factory.TakeBufferedWriter(this);

            messageWriter._startInfo           = startInfo;
            messageWriter._boundary            = boundary;
            messageWriter._startUri            = startUri;
            messageWriter._writeMessageHeaders = writeMessageHeaders;
            messageWriter._maxSizeInBytes      = maxMessageSize;
            ArraySegment <byte> messageData = messageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);

            _factory.ReturnMessageWriter(messageWriter);

            // if (WcfEventSource.Instance.MessageWrittenByEncoderIsEnabled() && messageData != null)
            // {
            //     WcfEventSource.Instance.MessageWrittenByEncoder(
            //         eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message),
            //         messageData.Count,
            //         this);
            // }
            //
            // if (MessageLogger.LogMessagesAtTransportLevel)
            // {
            //     string contentType = null;
            //     if (boundary != null)
            //         contentType = FormatContentType(boundary, startInfo ?? GenerateStartInfoString());
            //
            //     XmlDictionaryReader xmlDictionaryReader = XmlMtomReader.Create(messageData.Array, messageData.Offset, messageData.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, XmlDictionaryReaderQuotas.Max, int.MaxValue, null);
            //     MessageLogger.LogMessage(ref message, xmlDictionaryReader, MessageLoggingSource.TransportSend);
            // }

            return(messageData);
        }
Exemplo n.º 8
0
 void ReturnMessageWriter(MtomBufferedMessageWriter messageWriter)
 {
     bufferedWriterPool.Return(messageWriter);
 }
Exemplo n.º 9
0
        MtomBufferedMessageWriter TakeBufferedWriter()
        {
            if (bufferedWriterPool == null)
            {
                lock (thisLock)
                {
                    if (bufferedWriterPool == null)
                    {
                        bufferedWriterPool = new SynchronizedPool<MtomBufferedMessageWriter>(maxWritePoolSize);
                    }
                }
            }

            MtomBufferedMessageWriter messageWriter = bufferedWriterPool.Take();
            if (messageWriter == null)
            {
                messageWriter = new MtomBufferedMessageWriter(this);
                if (TD.WritePoolMissIsEnabled())
                {
                    TD.WritePoolMiss(messageWriter.GetType().Name);
                }
            }
            return messageWriter;
        }
 private MtomBufferedMessageWriter TakeBufferedWriter()
 {
     if (this.bufferedWriterPool == null)
     {
         lock (this.thisLock)
         {
             if (this.bufferedWriterPool == null)
             {
                 this.bufferedWriterPool = new SynchronizedPool<MtomBufferedMessageWriter>(this.maxWritePoolSize);
             }
         }
     }
     MtomBufferedMessageWriter writer = this.bufferedWriterPool.Take();
     if (writer == null)
     {
         writer = new MtomBufferedMessageWriter(this);
     }
     return writer;
 }
 private void ReturnMessageWriter(MtomBufferedMessageWriter messageWriter)
 {
     this.bufferedWriterPool.Return(messageWriter);
 }