title: Send/Receive GZip compressed MSMQ messages in C#
body: <p>I am trying to send large objects (>30MB) to a MSMQ queue. Due to the large amount of data we are are tring to send the idea was to GZip the objects prior to sending them, then unzipping them on the receiving end.</p>
  
  <p>However, writing the compressed stream to the <code>message.BodyStream</code> property seems to work, but not reading it out from there.
  I don't know what's wrong.</p>
  
  <pre><code>Message l_QueueMessage = new Message();
  l_QueueMessage.Priority = priority;
  
  using (MessageQueue l_Queue = CreateQueue())
  {
      GZipStream stream = new GZipStream(l_QueueMessage.BodyStream, CompressionMode.Compress);
  
      Formatter.Serialize(stream, message);
  
      l_Queue.Send(l_QueueMessage);
  }
  </code></pre>
  
  <p>The Formatter is a global property of type BinaryFormatter. This is used to serialize/deserialize to the type of object we want to send/receive, e.g. "ProductItem".</p>
  
  <p>The receving end looks like this:</p>
  
  <pre><code>GZipStream stream = new GZipStream(l_Message.BodyStream, CompressionMode.Decompress);
  
  object decompressedObject = Formatter.Deserialize(stream);
  
  ProductItem l_Item = decompressedObject as ProductItem;
  
  m_ProductReceived(sender, new MessageReceivedEventArgs&lt;ProductItem&gt;(l_Item));
  
  l_ProductQueue.BeginReceive();
  </code></pre>
  
  <p>I get an <code>EndOfStreamException "{"Unable to read beyond the end of the stream."}</code> trying to deserialize
  at System.IO.BinaryReader.ReadByte()</p>
  
  <p>Using the messageBodyStream property I actually circumvent the message.Formatter, which I don't initialize to anything, becasue I'm using my own ser/deser mechanism with the GZipStream. However, I am not sure if that's the correct way of doing this.</p>
  
  <p>What am I missing?
  Thanks!</p>