?
Solved

MSMQ BinaryFormatter. Convert to String

Posted on 2012-08-10
2
Medium Priority
?
1,228 Views
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()
        '''Next?
        msgText=?????????
************************************************************************
Any help is GREATLY appreciated
Tom
0
Comment
Question by:wherewasi
2 Comments
 
LVL 13

Accepted Solution

by:
Pryrates earned 2000 total points
ID: 38284965
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:
http://www.aspfree.com/c/a/ASP.NET/Using-MSMQ-in-Dot-Net-Using-VBNet-Sending-and-Receiving-Messages-Using-MSMQ-in-Dot-Net/
http://msdn.microsoft.com/en-us/library/ms978430.aspx

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.
0
 

Author Closing Comment

by:wherewasi
ID: 38305283
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,
Tom
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

840 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