How to read MSMQ message from VB6 application using .NET code?

I am writing a simple xml string in MSMQ from a VB6 application, but when I try to read a message from a queue in C # using XmlMessageFormatter, I get the following error:

"The name cannot start with '.' symbol"

How can I successfully read these messages using .Net code?

+1


source to share


4 answers


I believe you need to use ActiveXMessageFormatter and not XmlMessageFormatter. XmlMessageFormatter is for sending objects between .net applications. What you are sending is not xml but string. And not a .net string. According to the ActiveXMessageFormatter documentation, it is designed to:

Serializes or deserializes primitive data types and other objects or from the body of a message message queue using a format that is compatible with the MSMQ ActiveX Component



When submitting from vb6, you are using the msmq com. This is another name for the ActiveX interface. After getting the string using ActiveXMessageFormatter. Convert it to xml object explicitly.

+2


source


check your details first to make sure it is correct, as indicated by the error message. If so, read the data as text or binary first, remove the offensive ".", Then use xmlmessageformatter



0


source


I have bad news. I followed the advice provided and it didn't work.

I ended up creating a VC ++ COM object that sent messages to the queue from my .NET application so that the VC ++ COM receiver on the other hand could understand the message.

I suspect that you will need to create a VB6 COM object that you call from a .NET application to send messages.

It seems that mqao.dll uses COM objects, uses a different formatter than .NET, and even ActiveX does not work.

Obviously, this also implies two queues: one for legacy COM applications and one for .NET applications. This way you send the same message twice, once for each target client.

0


source


I just spent a whole day wrestling with messages being put into and read by MSMQ with the formatter hidden under so many abstractions and layer states that I have despaired of finding in this life. I built the following function as a brute-force attack on any msmq message that appears to contain at least some readable ASCII:

    private static string MsmqMsgBodyWtf(Message recalcitrantMsmqMessage, bool showHex = false, bool showChars = false)
    {
        recalcitrantMsmqMessage.Formatter = new ActiveXMessageFormatter();
        byte[] bytes = (byte[])recalcitrantMsmqMessage.Formatter.Read(recalcitrantMsmqMessage);
        StringBuilder dottedHex = new StringBuilder();
        StringBuilder dottedAscii = new StringBuilder();
        StringBuilder plainAscii = new StringBuilder();

        for (int i = 0; i < bytes.Length; i++)
        {
            byte b = bytes[i];

            string hexString;
            hexString = String.Format("{0:x2}", b);
            dottedHex.Append(hexString + ".");

            string charString = byte2char(b);
            string escapedCharString = (b > 31 && b < 128) ? charString : "?";
            dottedAscii.Append(escapedCharString + " .");
            plainAscii.Append(escapedCharString);
        }

        StringBuilder composedOutput = new StringBuilder(plainAscii.ToString());
        if (showHex || showChars) composedOutput.Append(System.Environment.NewLine);
        if (showHex) composedOutput.AppendLine(dottedHex.ToString());
        if (showChars) composedOutput.AppendLine(dottedAscii.ToString());

        return composedOutput.ToString(); ;
    }

      

Now I can download the messages and analyze them with other tools. Yippee!

0


source







All Articles