private bool HandleWriteStartBytes(IAsyncResult result) { this.connection.EndWrite(result); Microsoft.ServiceBus.Channels.StreamingConnectionHelper.StreamingOutputConnectionStream streamingOutputConnectionStream = new Microsoft.ServiceBus.Channels.StreamingConnectionHelper.StreamingOutputConnectionStream(this.connection, this.settings) { Immediate = !this.message.Properties.AllowOutputBatching }; Stream timeoutStream = new Microsoft.ServiceBus.Channels.TimeoutStream(streamingOutputConnectionStream, ref this.timeoutHelper); this.encoder.WriteMessage(this.message, timeoutStream); return(this.WriteEndBytes()); }
public static void WriteMessage(Message message, Microsoft.ServiceBus.Channels.IConnection connection, bool isRequest, Microsoft.ServiceBus.Channels.IConnectionOrientedTransportFactorySettings settings, ref TimeoutHelper timeoutHelper) { bool flag; byte[] envelopeEndBytes = null; if (message != null) { MessageEncoder encoder = settings.MessageEncoderFactory.Encoder; byte[] envelopeStartBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeStartBytes; if (!isRequest) { envelopeEndBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeEndBytes; flag = Microsoft.ServiceBus.Channels.TransferModeHelper.IsResponseStreamed(settings.TransferMode); } else { envelopeEndBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeEndFramingEndBytes; flag = Microsoft.ServiceBus.Channels.TransferModeHelper.IsRequestStreamed(settings.TransferMode); } if (!flag) { ArraySegment <byte> nums = encoder.WriteMessage(message, 2147483647, settings.BufferManager, (int)envelopeStartBytes.Length + 5); nums = Microsoft.ServiceBus.Channels.SingletonEncoder.EncodeMessageFrame(nums); Buffer.BlockCopy(envelopeStartBytes, 0, nums.Array, nums.Offset - (int)envelopeStartBytes.Length, (int)envelopeStartBytes.Length); connection.Write(nums.Array, nums.Offset - (int)envelopeStartBytes.Length, nums.Count + (int)envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), settings.BufferManager); } else { connection.Write(envelopeStartBytes, 0, (int)envelopeStartBytes.Length, false, timeoutHelper.RemainingTime()); Microsoft.ServiceBus.Channels.StreamingConnectionHelper.StreamingOutputConnectionStream streamingOutputConnectionStream = new Microsoft.ServiceBus.Channels.StreamingConnectionHelper.StreamingOutputConnectionStream(connection, settings) { Immediate = !message.Properties.AllowOutputBatching }; encoder.WriteMessage(message, new Microsoft.ServiceBus.Channels.TimeoutStream(streamingOutputConnectionStream, ref timeoutHelper)); } } else if (isRequest) { envelopeEndBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EndBytes; } if (envelopeEndBytes != null) { connection.Write(envelopeEndBytes, 0, (int)envelopeEndBytes.Length, true, timeoutHelper.RemainingTime()); } }