// OnCreateBufferedCopy / OnWriteBodyContents can only be called once - protected by state on Message (either copied or written once) protected override BodyWriter OnCreateBufferedCopy(int maxBufferSize) { using (BufferManagerOutputStream bufferedStream = new BufferManagerOutputStream(SR.MaxReceivedMessageSizeExceeded("{0}"), maxBufferSize)) { using (XmlDictionaryWriter writer = new XmlByteStreamWriter(bufferedStream, true)) { OnWriteBodyContents(writer); writer.Flush(); int size; byte[] bytesArray = bufferedStream.ToArray(out size); ByteStreamBufferedMessageData bufferedMessageData = new ByteStreamBufferedMessageData(new ArraySegment <byte>(bytesArray, 0, size)); return(new BufferedBodyWriter(bufferedMessageData)); } } }
public override void WriteMessage(Message message, Stream stream) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } if (stream == null) { throw FxTrace.Exception.ArgumentNull("stream"); } ThrowIfMismatchedMessageVersion(message); EventTraceActivity eventTraceActivity = null; if (TD.ByteStreamMessageEncodingStartIsEnabled()) { eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message); TD.ByteStreamMessageEncodingStart(eventTraceActivity); } message.Properties.Encoder = this; if (MessageLogger.LogMessagesAtTransportLevel) { MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend); } using (XmlWriter writer = new XmlByteStreamWriter(stream, false)) { message.WriteMessage(writer); writer.Flush(); } if (SMTD.StreamedMessageWrittenByEncoderIsEnabled()) { SMTD.StreamedMessageWrittenByEncoder(eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message)); } }
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } if (bufferManager == null) { throw FxTrace.Exception.ArgumentNull("bufferManager"); } if (maxMessageSize < 0) { throw FxTrace.Exception.ArgumentOutOfRange("maxMessageSize", maxMessageSize, SR.ArgumentOutOfMinRange(0)); } if (messageOffset < 0) { throw FxTrace.Exception.ArgumentOutOfRange("messageOffset", messageOffset, SR.ArgumentOutOfMinRange(0)); } EventTraceActivity eventTraceActivity = null; if (TD.ByteStreamMessageEncodingStartIsEnabled()) { eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message); TD.ByteStreamMessageEncodingStart(eventTraceActivity); } ThrowIfMismatchedMessageVersion(message); message.Properties.Encoder = this; ArraySegment<byte> messageBuffer; int size; using (BufferManagerOutputStream stream = new BufferManagerOutputStream(maxSentMessageSizeExceededResourceString, 0, maxMessageSize, bufferManager)) { stream.Skip(messageOffset); using (XmlWriter writer = new XmlByteStreamWriter(stream, true)) { message.WriteMessage(writer); writer.Flush(); byte[] bytes = stream.ToArray(out size); messageBuffer = new ArraySegment<byte>(bytes, messageOffset, size - messageOffset); } } if (SMTD.MessageWrittenByEncoderIsEnabled()) { SMTD.MessageWrittenByEncoder( eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message), messageBuffer.Count, this); } if (MessageLogger.LogMessagesAtTransportLevel) { // DevDiv#486728 // Don't pass in a buffer manager to avoid returning 'messageBuffer" to the bufferManager twice. ByteStreamBufferedMessageData messageData = new ByteStreamBufferedMessageData(messageBuffer, null); using (XmlReader reader = new XmlBufferedByteStreamReader(messageData, this.quotas)) { MessageLogger.LogMessage(ref message, reader, MessageLoggingSource.TransportSend); } } return messageBuffer; }
public override ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } if (bufferManager == null) { throw FxTrace.Exception.ArgumentNull("bufferManager"); } if (maxMessageSize < 0) { throw FxTrace.Exception.ArgumentOutOfRange("maxMessageSize", maxMessageSize, SR.ArgumentOutOfMinRange(0)); } if (messageOffset < 0) { throw FxTrace.Exception.ArgumentOutOfRange("messageOffset", messageOffset, SR.ArgumentOutOfMinRange(0)); } EventTraceActivity eventTraceActivity = null; if (TD.ByteStreamMessageEncodingStartIsEnabled()) { eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message); TD.ByteStreamMessageEncodingStart(eventTraceActivity); } ThrowIfMismatchedMessageVersion(message); message.Properties.Encoder = this; ArraySegment <byte> messageBuffer; int size; using (BufferManagerOutputStream stream = new BufferManagerOutputStream(maxSentMessageSizeExceededResourceString, 0, maxMessageSize, bufferManager)) { stream.Skip(messageOffset); using (XmlWriter writer = new XmlByteStreamWriter(stream, true)) { message.WriteMessage(writer); writer.Flush(); byte[] bytes = stream.ToArray(out size); messageBuffer = new ArraySegment <byte>(bytes, messageOffset, size - messageOffset); } } if (SMTD.MessageWrittenByEncoderIsEnabled()) { SMTD.MessageWrittenByEncoder( eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message), messageBuffer.Count, this); } if (MessageLogger.LogMessagesAtTransportLevel) { // DevDiv#486728 // Don't pass in a buffer manager to avoid returning 'messageBuffer" to the bufferManager twice. ByteStreamBufferedMessageData messageData = new ByteStreamBufferedMessageData(messageBuffer, null); using (XmlReader reader = new XmlBufferedByteStreamReader(messageData, this.quotas)) { MessageLogger.LogMessage(ref message, reader, MessageLoggingSource.TransportSend); } } return(messageBuffer); }