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); }
public MtomMessageEncoder(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, int maxBufferSize, XmlDictionaryReaderQuotas quotas, MtomMessageEncoderFactory factory) { if (version == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(version)); } if (writeEncoding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writeEncoding)); } _factory = factory; TextEncoderDefaults.ValidateEncoding(writeEncoding); _writeEncoding = writeEncoding; MaxReadPoolSize = maxReadPoolSize; MaxWritePoolSize = maxWritePoolSize; ReaderQuotas = new XmlDictionaryReaderQuotas(); quotas.CopyTo(ReaderQuotas); _bufferedReadReaderQuotas = EncoderHelpers.GetBufferedReadQuotas(ReaderQuotas); MaxBufferSize = maxBufferSize; _version = version; _contentType = GetContentType(out _boundary); }
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); }
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); }
public MtomMessageEncoder(MtomMessageEncoderFactory owner) { version = owner.MessageVersion; encoding = owner.Owner.WriteEncoding; quotas = owner.Owner.ReaderQuotas; }
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)); } }
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); }
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); }
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); }
public MtomMessageEncoder(MtomMessageEncoderFactory owner) { version = owner.MessageVersion; encoding = owner.Owner.WriteEncoding; }
public MtomMessageEncoder (MtomMessageEncoderFactory owner) { version = owner.MessageVersion; encoding = owner.Owner.WriteEncoding; }
public MtomMessageEncoder (MtomMessageEncoderFactory owner) { version = owner.MessageVersion; encoding = owner.Owner.WriteEncoding; quotas = owner.Owner.ReaderQuotas; }