title: Send binary message in MSMQ
body: <p>In a .NET service, I'd like to send the content of a stream in a MSMQ message. I receive a Stream object from WCF (which can be an image, a .doc file or anything else) and I would just like to put the content in MSMQ. I tried setting the System.Messaging.Message.BodyStream property to the stream object, but I receive a "Method not supported" error when I try to Send the message.</p>
  
  <p>Does anyone have a sample or tutorial on how to do that ?</p>
  
  <p>I'm looking for something like this :</p>
  
  <p>Message contract :</p>
  
  <pre><code>    &lt;MessageContract()&gt; _
     Class UploadStreamMessage
          &lt;MessageHeader()&gt; _
          Public guidCaller As Guid
          &lt;MessageBodyMember()&gt; _
          Public data As Stream
      End Class
  </code></pre>
  
  <p>And then the WriteToMSMQ method implementation :</p>
  
  <pre><code>   &lt;OperationBehavior(TransactionScopeRequired:=True, Impersonation:=ImpersonationOption.Required)&gt; _
     Public Sub WriteToMSMQ (ByVal stream As IServiceMSMQ.UploadStreamMessage) Implements IServiceMSMQ.WriteToMSMQ 
  
  Using queue As New MessageQueue(NOM_QUEUE)
  
      Dim msmqMessage As New Message
      msmqMessage = New System.Messaging.Message()
      msmqMessage.Body = stream.data
      queue.Send(msmqMessage, transaction)
      stream.data.Close()
  
  End Using
  </code></pre>
  
  <p>Thanks !   </p>