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); }
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); }
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); }