-1

A Windows service when trying to access the .Body property of a MSMQ message object throws an EOleException - but only when the Xml document contained in this message has an empty list node.

The EOleException message complains about insufficient memory (exception code -2147024882). Since the exception only occurs with the smallest possible Xml document, memory cannot be the real issue. The next thing that comes to mind is a problem with access rights but then again all "good" messages (as described below) are processed without problems.

The exception can be reproduced under any thinkable condition ("bad" message first, many "good" messages first - then "bad" message, run in debugger or just logging the exception); it doesn't matter if the code shown below is run as a service or as a simple excecutable.

Using the same COM object (MSMQ.MSMQQueueInfo) from within a VBScript on the same machine does not produce any errors.

Accessing any other properties apart from .Body doesn't throw an exception so the message object instance seems to be received sucessfully. Also the transaction receiving the message can be comitted sucessfully if the .Body property is not accessed.


Windows Service code

//...
qInfo    := CreateOleObject('MSMQ.MSMQQueueInfo');
qTxDisp  := CreateOleObject('MSMQ.MSMQTransactionDispenser');
//...
qTx := qTxDisp.BeginTransaction;
qMessage := qQueue.Receive(qTx, False, True, 0);
//...
sBody := qMessage.Body; //throws EOleException

The qMessage.BodyLength property returns the value 165 for "bad" messages as shown below.

"Bad" message

<?xml version="1.0" encoding="Windows-1252"?>
<response space="" Message="Entry_7">
    <query>
        <entrylist count="0">
        </entrylist>
    </query>
</response>

This message reliably makes the service code throw an EOleExecption.

"Good" message

<?xml version="1.0" encoding="Windows-1252"?>
<response space="" Message="Entry_7">
    <query>
        <entrylist count="2">
            <entry>
                <abc>123</abc>
                <def>456</def>
            </entry>
            <entry>
                <abc>789</abc>
                <def>000</def>
            </entry>
        </entrylist>
    </query>
</response>

This message is reliably processed without problems.

The problem first occured when moving the service from a Win2003 machine to a Win2008 (32-bit Standard).

Filburt
  • 17,626
  • 12
  • 64
  • 115
  • What "OLE Exception" does it throw? What is the exact error message? Without details, your question is much harder to answer - there are dozens (if not hundreds) of EOleException reasons, and the exact error message will help narrow that down. (Posting this type question is like calling your doctor's office and saying "I don't feel well. What kind of medicine do I need?" - you're not going to get an answer without a lot more information than that, are you?) – Ken White Nov 17 '10 at 19:13
  • @Ken Your comment seems a bit harsh because I did provide a good part more information than all those posts just repeating the title in the body. However I did not provide the exception message. As you can see in my update the message states that the problem is insuffient memory which is plain nonsense. – Filburt Nov 18 '10 at 09:04
  • @Ken ... and to stick with your medic picture I quite clearly state what I actually do that makes me hurt. – Filburt Nov 18 '10 at 09:14
  • @Ken ... and fgim (BEFORE I posted here) didn't yield that many (hundreds?) EOleExceptions reasons that were really useful. – Filburt Nov 18 '10 at 09:18
  • Trying to help, installed MSMQ on Vista Business but without success, the ActiveX for MSMQ does not appear in the selection in the import Dialog in Delphi. Is the ActiveX included in the HTTP/IIS adapter subcomponent or should it be there after installing the core components of MSMQ (top level option in the installer)? – mjn Nov 21 '10 at 10:13
  • 1
    What does `VarTypeAsText(VarType(qMessage.Body))` and `qMessage.BodyLength` return? – The_Fox Nov 22 '10 at 12:50
  • @The_Fox qMessage.BodyLength returns the value 165 for "bad" messages. qMessage.Body cannot be accessed in any way and will always throw said EOleException. – Filburt Nov 23 '10 at 13:01
  • @Filburt: I have no idea what the problem is, maybe it is a the posting side and not the receiving one? (posting malformed message?) – The_Fox Nov 23 '10 at 14:19
  • @The_Fox: The message should be okay since I can read it just fine using VBScript and the same component (MSMQ.MSMQQueueInfo). To me it looks like something in the way Delphi uses this component. – Filburt Nov 30 '10 at 10:25

1 Answers1

0

If the VBScript works fine, then I guess that it is something in the interaction between MSMQ and the Delphi service.

Have you tried to run the Delphi code in a standalone application?

I have not yet worked with MSMQ, but maybe you can also try to use a non transactional read from the message queue to see if it makes a difference (reduce the code to be as small/simple as possble).

A potential reason could be a different (newer) MSXML library on the Win2008 machine.

mjn
  • 36,362
  • 28
  • 176
  • 378
  • We tried running it in a standalone app already - this way we narrowed it down to the line where we're accessing the .Body property. MSXML shouldn't be the problem because a this point we're handling the .Body data as a simple string (we also tried WideString). – Filburt Nov 19 '10 at 08:27
  • Leaving out the transaction would be merely of diagnostic value since we must not run this process without transactions. – Filburt Nov 24 '10 at 12:33