コード例 #1
0
            public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bufferManager"));
                }
                UTF8BufferedMessageData messageData = this.TakeBufferedReader();

                messageData.Encoding = TextMessageEncoderFactory.GetEncodingFromContentType(contentType, this.contentEncodingMap);
                messageData.Open(buffer, bufferManager);
                RecycledMessageState recycledMessageState = messageData.TakeMessageState();

                if (recycledMessageState == null)
                {
                    recycledMessageState = new RecycledMessageState();
                }
                Message message = new BufferedMessage(messageData, recycledMessageState)
                {
                    Properties = { Encoder = this }
                };

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }
                return(message);
            }
コード例 #2
0
        XmlReader TakeStreamedReader(Stream stream, string contentType)
        {
            if (streamedReaderPool == null)
            {
                lock (thisLock)
                {
                    if (streamedReaderPool == null)
                    {
                        streamedReaderPool = new SynchronizedPool <XmlDictionaryReader>(maxReadPoolSize);
                    }
                }
            }
            XmlDictionaryReader xmlReader = streamedReaderPool.Take();

            try
            {
                if (contentType == null || IsMTOMContentType(contentType))
                {
                    if (xmlReader != null && xmlReader is IXmlMtomReaderInitializer)
                    {
                        ((IXmlMtomReaderInitializer)xmlReader).SetInput(stream, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, this.readerQuotas, this.maxBufferSize, onStreamedReaderClose);
                    }
                    else
                    {
                        xmlReader = XmlDictionaryReader.CreateMtomReader(stream, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, this.readerQuotas, this.maxBufferSize, onStreamedReaderClose);
                        if (TD.ReadPoolMissIsEnabled())
                        {
                            TD.ReadPoolMiss(xmlReader.GetType().Name);
                        }
                    }
                }
                else
                {
                    if (xmlReader != null && xmlReader is IXmlTextReaderInitializer)
                    {
                        ((IXmlTextReaderInitializer)xmlReader).SetInput(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, this.contentEncodingMap), this.readerQuotas, onStreamedReaderClose);
                    }
                    else
                    {
                        xmlReader = XmlDictionaryReader.CreateTextReader(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, this.contentEncodingMap), this.readerQuotas, onStreamedReaderClose);
                        if (TD.ReadPoolMissIsEnabled())
                        {
                            TD.ReadPoolMiss(xmlReader.GetType().Name);
                        }
                    }
                }
            }
            catch (FormatException fe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.GetString(SR.SFxErrorCreatingMtomReader), fe));
            }
            catch (XmlException xe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.GetString(SR.SFxErrorCreatingMtomReader), xe));
            }

            return(xmlReader);
        }
コード例 #3
0
            public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
            {
                if (stream == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("stream"));
                }

                if (WebTD.JsonMessageDecodingStartIsEnabled())
                {
                    WebTD.JsonMessageDecodingStart();
                }

                XmlReader reader  = TakeStreamedReader(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, JsonMessageEncoderFactory.ApplicationJsonContentEncoding));
                Message   message = Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion.None);

                message.Properties.Encoder = this;

                if (SMTD.StreamedMessageReadByEncoderIsEnabled())
                {
                    SMTD.StreamedMessageReadByEncoder(EventTraceActivityHelper.TryExtractActivity(message, true));
                }

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }
                return(message);
            }
コード例 #4
0
        internal bool IsTextContentType(string contentType)
        {
            string mediaType            = TextMessageEncoderFactory.GetMediaType(this.version);
            string supportedContentType = TextMessageEncoderFactory.GetContentType(mediaType, this.writeEncoding);

            return(base.IsContentTypeSupported(contentType, supportedContentType, mediaType));
        }
コード例 #5
0
ファイル: MtomMessageEncoder.cs プロジェクト: HongGit/wcf
        internal XmlReader TakeStreamedReader(Stream stream, string contentType, bool isMtomContentType)
        {
            if (_streamedReaderPool == null)
            {
                lock (_thisLock)
                {
                    if (_streamedReaderPool == null)
                    {
                        _streamedReaderPool = new SynchronizedPool <XmlDictionaryReader>(MaxReadPoolSize);
                    }
                }
            }
            XmlDictionaryReader xmlReader = _streamedReaderPool.Take();

            try
            {
                if (contentType == null || isMtomContentType)
                {
                    if (xmlReader != null && xmlReader is IXmlMtomReaderInitializer)
                    {
                        ((IXmlMtomReaderInitializer)xmlReader).SetInput(stream, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, ReaderQuotas, MaxBufferSize, _onStreamedReaderClose);
                    }
                    else
                    {
                        xmlReader = XmlMtomReader.Create(stream, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, ReaderQuotas, MaxBufferSize, _onStreamedReaderClose);
                        if (WcfEventSource.Instance.ReadPoolMissIsEnabled())
                        {
                            WcfEventSource.Instance.ReadPoolMiss(xmlReader.GetType().Name);
                        }
                    }
                }
                else
                {
                    if (xmlReader != null && xmlReader is IXmlTextReaderInitializer)
                    {
                        ((IXmlTextReaderInitializer)xmlReader).SetInput(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, ContentEncodingMap), ReaderQuotas, _onStreamedReaderClose);
                    }
                    else
                    {
                        xmlReader = XmlDictionaryReader.CreateTextReader(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, ContentEncodingMap), ReaderQuotas, _onStreamedReaderClose);
                        if (WcfEventSource.Instance.ReadPoolMissIsEnabled())
                        {
                            WcfEventSource.Instance.ReadPoolMiss(xmlReader.GetType().Name);
                        }
                    }
                }
            }
            catch (FormatException fe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.SFxErrorCreatingMtomReader, fe));
            }
            catch (XmlException xe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.SFxErrorCreatingMtomReader, xe));
            }

            return(xmlReader);
        }
コード例 #6
0
        internal bool IsTextContentType(string contentType)
        {
            // check for Text contentType: text/xml or application/soap+xml
            string textMediaType   = TextMessageEncoderFactory.GetMediaType(version);
            string textContentType = TextMessageEncoderFactory.GetContentType(textMediaType, writeEncoding);

            return(IsContentTypeSupported(contentType, textContentType, textMediaType));
        }
コード例 #7
0
 static TextMessageEncoderFactory.ContentEncoding[] GetContentEncodingMap(string mediaType)
 {
     Encoding[] readEncodings = TextMessageEncoderFactory.GetSupportedEncodings();
     TextMessageEncoderFactory.ContentEncoding[] map = new TextMessageEncoderFactory.ContentEncoding[readEncodings.Length];
     for (int i = 0; i < readEncodings.Length; i++)
     {
         TextMessageEncoderFactory.ContentEncoding contentEncoding = new TextMessageEncoderFactory.ContentEncoding();
         contentEncoding.contentType = WebMessageEncoderFactory.GetContentType(mediaType, readEncodings[i]);
         contentEncoding.encoding    = readEncodings[i];
         map[i] = contentEncoding;
     }
     return(map);
 }
コード例 #8
0
        private static ContentEncoding[] GetContentEncodingMap(MessageVersion version)
        {
            Encoding[] readEncodings = TextMessageEncoderFactory.GetSupportedEncodings();
            string     media         = GetMediaType(version);

            ContentEncoding[] map = new ContentEncoding[readEncodings.Length];
            for (int i = 0; i < readEncodings.Length; i++)
            {
                ContentEncoding contentEncoding = new ContentEncoding();
                contentEncoding.contentType = GetContentType(media, readEncodings[i]);
                contentEncoding.encoding    = readEncodings[i];
                map[i] = contentEncoding;
            }
            return(map);
        }
コード例 #9
0
            public TextMessageEncoder(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas)
            {
                if (version == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("version");
                }
                if (writeEncoding == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
                }

                TextEncoderDefaults.ValidateEncoding(writeEncoding);
                this.writeEncoding   = writeEncoding;
                optimizeWriteForUTF8 = IsUTF8Encoding(writeEncoding);

                thisLock = new object();

                this.version          = version;
                this.maxReadPoolSize  = maxReadPoolSize;
                this.maxWritePoolSize = maxWritePoolSize;

                this.readerQuotas = new XmlDictionaryReaderQuotas();
                quotas.CopyTo(this.readerQuotas);

                this.bufferedReadReaderQuotas = EncoderHelpers.GetBufferedReadQuotas(this.readerQuotas);

                this.onStreamedReaderClose = new OnXmlDictionaryReaderClose(ReturnStreamedReader);

                this.mediaType   = TextMessageEncoderFactory.GetMediaType(version);
                this.contentType = TextMessageEncoderFactory.GetContentType(mediaType, writeEncoding);
                if (version.Envelope == EnvelopeVersion.Soap12)
                {
                    contentEncodingMap = TextMessageEncoderFactory.Soap12Content;
                }
                else if (version.Envelope == EnvelopeVersion.Soap11)
                {
                    contentEncodingMap = TextMessageEncoderFactory.Soap11Content;
                }
                else if (version.Envelope == EnvelopeVersion.None)
                {
                    contentEncodingMap = TextMessageEncoderFactory.SoapNoneContent;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.GetString(SR.EnvelopeVersionNotSupported, version.Envelope)));
                }
            }
コード例 #10
0
            public TextMessageEncoder(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas)
            {
                if (version == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("version");
                }
                if (writeEncoding == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
                }

                TextEncoderDefaults.ValidateEncoding(writeEncoding);
                _writeEncoding        = writeEncoding;
                _optimizeWriteForUTF8 = IsUTF8Encoding(writeEncoding);

                _thisLock = new object();

                _version          = version;
                _maxReadPoolSize  = maxReadPoolSize;
                _maxWritePoolSize = maxWritePoolSize;

                _readerQuotas = new XmlDictionaryReaderQuotas();
                quotas.CopyTo(_readerQuotas);
                _bufferedReadReaderQuotas = EncoderHelpers.GetBufferedReadQuotas(_readerQuotas);

                _mediaType   = TextMessageEncoderFactory.GetMediaType(version);
                _contentType = TextMessageEncoderFactory.GetContentType(_mediaType, writeEncoding);
                if (version.Envelope == EnvelopeVersion.Soap12)
                {
                    _contentEncodingMap = TextMessageEncoderFactory.Soap12Content;
                }
                else if (version.Envelope == EnvelopeVersion.Soap11)
                {
                    // public profile does not allow SOAP1.1/WSA1.0. However, the EnvelopeVersion 1.1 is supported. Need to know what the implications are here
                    // but I think that it's not necessary to have here since we're a sender in N only.
                    _contentEncodingMap = TextMessageEncoderFactory.Soap11Content;
                }
                else if (version.Envelope == EnvelopeVersion.None)
                {
                    _contentEncodingMap = TextMessageEncoderFactory.SoapNoneContent;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  string.Format(SRServiceModel.EnvelopeVersionNotSupported, version.Envelope)));
                }
            }
コード例 #11
0
            public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bufferManager"));
                }

                if (WebTD.JsonMessageDecodingStartIsEnabled())
                {
                    WebTD.JsonMessageDecodingStart();
                }

                Message message;

                JsonBufferedMessageData messageData = TakeBufferedReader();

                messageData.Encoding = TextMessageEncoderFactory.GetEncodingFromContentType(contentType, JsonMessageEncoderFactory.ApplicationJsonContentEncoding);
                messageData.Open(buffer, bufferManager);
                RecycledMessageState messageState = messageData.TakeMessageState();

                if (messageState == null)
                {
                    messageState = new RecycledMessageState();
                }
                message = new BufferedMessage(messageData, messageState);

                message.Properties.Encoder = this;

                if (SMTD.MessageReadByEncoderIsEnabled() && buffer != null)
                {
                    SMTD.MessageReadByEncoder(
                        EventTraceActivityHelper.TryExtractActivity(message, true),
                        buffer.Count,
                        this);
                }

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }

                return(message);
            }
コード例 #12
0
        private XmlReader TakeStreamedReader(Stream stream, string contentType)
        {
            if (this.streamedReaderPool == null)
            {
                lock (this.thisLock)
                {
                    if (this.streamedReaderPool == null)
                    {
                        this.streamedReaderPool = new SynchronizedPool <XmlDictionaryReader>(this.maxReadPoolSize);
                    }
                }
            }
            XmlDictionaryReader reader = this.streamedReaderPool.Take();

            try
            {
                if ((contentType == null) || this.IsMTOMContentType(contentType))
                {
                    if ((reader != null) && (reader is IXmlMtomReaderInitializer))
                    {
                        ((IXmlMtomReaderInitializer)reader).SetInput(stream, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, this.readerQuotas, this.maxBufferSize, this.onStreamedReaderClose);
                        return(reader);
                    }
                    return(XmlDictionaryReader.CreateMtomReader(stream, MtomMessageEncoderFactory.GetSupportedEncodings(), contentType, this.readerQuotas, this.maxBufferSize, this.onStreamedReaderClose));
                }
                if ((reader != null) && (reader is IXmlTextReaderInitializer))
                {
                    ((IXmlTextReaderInitializer)reader).SetInput(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, this.contentEncodingMap), this.readerQuotas, this.onStreamedReaderClose);
                    return(reader);
                }
                reader = XmlDictionaryReader.CreateTextReader(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, this.contentEncodingMap), this.readerQuotas, this.onStreamedReaderClose);
            }
            catch (FormatException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorCreatingMtomReader"), exception));
            }
            catch (XmlException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorCreatingMtomReader"), exception2));
            }
            return(reader);
        }
コード例 #13
0
            public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
            {
                if (stream == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("stream"));
                }
                Message message = Message.CreateMessage(this.TakeStreamedReader(stream, TextMessageEncoderFactory.GetEncodingFromContentType(contentType, this.contentEncodingMap)), maxSizeOfHeaders, this.version);

                message.Properties.Encoder = this;
                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }
                return(message);
            }
コード例 #14
0
            protected override XmlDictionaryReader TakeXmlReader()
            {
                try
                {
                    ArraySegment <byte> buffer = this.Buffer;

                    XmlDictionaryReader xmlReader = readerPool.Take();
                    if (ContentType == null || messageEncoder.IsMTOMContentType(ContentType))
                    {
                        if (xmlReader != null && xmlReader is IXmlMtomReaderInitializer)
                        {
                            ((IXmlMtomReaderInitializer)xmlReader).SetInput(buffer.Array, buffer.Offset, buffer.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), ContentType, this.Quotas, this.messageEncoder.MaxBufferSize, onClose);
                        }
                        else
                        {
                            xmlReader = XmlDictionaryReader.CreateMtomReader(buffer.Array, buffer.Offset, buffer.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), ContentType, this.Quotas, this.messageEncoder.MaxBufferSize, onClose);
                            if (TD.ReadPoolMissIsEnabled())
                            {
                                TD.ReadPoolMiss(xmlReader.GetType().Name);
                            }
                        }
                    }
                    else
                    {
                        if (xmlReader != null && xmlReader is IXmlTextReaderInitializer)
                        {
                            ((IXmlTextReaderInitializer)xmlReader).SetInput(buffer.Array, buffer.Offset, buffer.Count, TextMessageEncoderFactory.GetEncodingFromContentType(ContentType, this.messageEncoder.contentEncodingMap), this.Quotas, onClose);
                        }
                        else
                        {
                            xmlReader = XmlDictionaryReader.CreateTextReader(buffer.Array, buffer.Offset, buffer.Count, TextMessageEncoderFactory.GetEncodingFromContentType(ContentType, this.messageEncoder.contentEncodingMap), this.Quotas, onClose);
                            if (TD.ReadPoolMissIsEnabled())
                            {
                                TD.ReadPoolMiss(xmlReader.GetType().Name);
                            }
                        }
                    }
                    return(xmlReader);
                }
                catch (FormatException fe)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                                  SR.GetString(SR.SFxErrorCreatingMtomReader), fe));
                }
                catch (XmlException xe)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                                  SR.GetString(SR.SFxErrorCreatingMtomReader), xe));
                }
            }
コード例 #15
0
            protected override XmlDictionaryReader TakeXmlReader()
            {
                XmlDictionaryReader reader2;

                try
                {
                    ArraySegment <byte> buffer = base.Buffer;
                    XmlDictionaryReader reader = this.readerPool.Take();
                    if ((this.ContentType == null) || this.messageEncoder.IsMTOMContentType(this.ContentType))
                    {
                        if ((reader != null) && (reader is IXmlMtomReaderInitializer))
                        {
                            ((IXmlMtomReaderInitializer)reader).SetInput(buffer.Array, buffer.Offset, buffer.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), this.ContentType, this.messageEncoder.ReaderQuotas, this.messageEncoder.MaxBufferSize, this.onClose);
                        }
                        else
                        {
                            reader = XmlDictionaryReader.CreateMtomReader(buffer.Array, buffer.Offset, buffer.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), this.ContentType, this.messageEncoder.ReaderQuotas, this.messageEncoder.MaxBufferSize, this.onClose);
                        }
                    }
                    else if ((reader != null) && (reader is IXmlTextReaderInitializer))
                    {
                        ((IXmlTextReaderInitializer)reader).SetInput(buffer.Array, buffer.Offset, buffer.Count, TextMessageEncoderFactory.GetEncodingFromContentType(this.ContentType, this.messageEncoder.contentEncodingMap), this.messageEncoder.ReaderQuotas, this.onClose);
                    }
                    else
                    {
                        reader = XmlDictionaryReader.CreateTextReader(buffer.Array, buffer.Offset, buffer.Count, TextMessageEncoderFactory.GetEncodingFromContentType(this.ContentType, this.messageEncoder.contentEncodingMap), this.messageEncoder.ReaderQuotas, this.onClose);
                    }
                    reader2 = reader;
                }
                catch (FormatException exception)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorCreatingMtomReader"), exception));
                }
                catch (XmlException exception2)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorCreatingMtomReader"), exception2));
                }
                return(reader2);
            }