Beispiel #1
0
        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);
        }
Beispiel #2
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));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
            public TextMessageEncoder(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas)
            {
                if (version == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(version));
                }
                if (writeEncoding == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writeEncoding));
                }

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

                thisLock = new object();

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

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

                bufferedReadReaderQuotas = EncoderHelpers.GetBufferedReadQuotas(readerQuotas);

                onStreamedReaderClose = new OnXmlDictionaryReaderClose(ReturnStreamedReader);

                mediaType   = TextMessageEncoderFactory.GetMediaType(version);
                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.Format(SR.EnvelopeVersionNotSupported, version.Envelope)));
                }
            }
Beispiel #5
0
            protected override XmlDictionaryReader TakeXmlReader()
            {
                try
                {
                    ArraySegment <byte> buffer = 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, Quotas, _messageEncoder.MaxBufferSize, _onClose);
                        }
                        else
                        {
                            xmlReader = XmlMtomReader.Create(buffer.Array, buffer.Offset, buffer.Count, MtomMessageEncoderFactory.GetSupportedEncodings(), _contentType, Quotas, _messageEncoder.MaxBufferSize, _onClose);
                            // if (WcfEventSource.Instance.ReadPoolMissIsEnabled())
                            // {
                            //     WcfEventSource.Instance.ReadPoolMiss(xmlReader.GetType().Name);
                            // }
                        }
                    }
                    else
                    {
                        if (xmlReader != null && xmlReader is IXmlTextReaderInitializer)
                        {
                            ((IXmlTextReaderInitializer)xmlReader).SetInput(buffer.Array, buffer.Offset, buffer.Count, TextMessageEncoderFactory.GetEncodingFromContentType(_contentType, _messageEncoder._factory.ContentEncodingMap), Quotas, _onClose);
                        }
                        else
                        {
                            xmlReader = XmlDictionaryReader.CreateTextReader(buffer.Array, buffer.Offset, buffer.Count, TextMessageEncoderFactory.GetEncodingFromContentType(_contentType, _messageEncoder._factory.ContentEncodingMap), Quotas, _onClose);
                            // if (WcfEventSource.Instance.ReadPoolMissIsEnabled())
                            // {
                            //     WcfEventSource.Instance.ReadPoolMiss(xmlReader.GetType().Name);
                            // }
                        }
                    }
                    return(xmlReader);
                }
                catch (FormatException fe)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                                  SR.SFxErrorCreatingMtomReader, fe));
                }
                catch (XmlException xe)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                                  SR.SFxErrorCreatingMtomReader, xe));
                }
            }