MSMQ BinaryFormatter. Convert to String

Posted on 2012-08-10
Last Modified: 2012-08-17
Hi Guys,
I'm really struggling with this.  I need to be able to receive a message from a MSMQ and convert the message to a string.  The examples I've seen (from MS) all convert the message to a bitmap which is not gonna help me.  
Here's the beginning of the code

    Private Sub qQueueForReceiving_ReceiveCompleted(ByVal sender As Object, ByVal e As System.Messaging.ReceiveCompletedEventArgs) Handles qQueueForReceiving.ReceiveCompleted
        Dim msgText As String
        Dim eMsg As Message
        'Get message from event arguments (e)
        eMsg = e.Message
        eMsg.Formatter = New BinaryMessageFormatter()
Any help is GREATLY appreciated
Question by:wherewasi
    LVL 13

    Accepted Solution

    you can try something like that:
    Dim eMsg As Messaging.Message
    Dim Br As BinaryReader
    Dim msgText As String
     m = eMsg.Receive(New TimeSpan(0, 0, 3))
     Br = New BinaryReader(m.BodyStream)
     msgText  = New String(Br.ReadChars(CInt(m.BodyStream.Length)))

    Open in new window

    check out these links:

    You are sure that the message is encoded in binary style?
    It is possible to store MSMQ in Xml format. That makes it easier to process the message and you can look at the content in the queue itself - makes bug tracing much easier.

    Author Closing Comment

    Thanks.  Now I have another question.

    I have legacy VB for some software that is not going to be upgraded to VB .Net any time soon.  I want to use (as the receiving application)  an MSMQ Receiver/Server that is written in VB .Net.  

    The sending application seems to send a string.  If I decode using any of the Formatters available in .Net I get garbage (as with the ActiveXFormatter) or I get errors/exceptions. .  Is there a simple solution?

    Thanks again,

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now