Hello,
I have created a codeunit (code see below) and a form with a button. The OnPush trigger of the Button calls the function SendMSMQ() of the codeunit.
If I run the codeunit and I click the button in my form, an error message comes up:
The stream has returned a read error
I spent already one whole day to find out whats wrong, but I couldn't.
If I set the property WithEvents of CC2 to NO I can see the
message under Message queue tool of XP with the text Hello world in it. If I set it to yes again, the message seems to be collected from the event, because not visible anymore under the message queue manager of Windows XP.
I found out the error happens on execution of following line:
StreamIn.READTEXT(Text, MAXSTRLEN(Text));
Does anybody have an idea whats wrong?
Thanks a lot!
Here's the code of the codeunit:
OnRun()
IF ISCLEAR(CC2) THEN
CREATE(CC2);
IF ISCLEAR(MQBus) THEN
CREATE(MQBus);
CC2.AddBusAdapter(MQBus,1);
MQBus.OpenReceiveQueue('.\private$\navision',0,0);
SendMSMQ()
MQBus.OpenWriteQueue('.\private$\navision',0,0);
OutMsg := CC2.CreateoutMessage('Message queue://');
StreamOut := OutMsg.GetStream();
StreamOut.WRITETEXT('Hello World');
OutMsg.Send(0);
CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
InMsg := InMessage;
StreamIn := InMsg.GetStream();
StreamIn.READTEXT(Text, MAXSTRLEN(Text));
MESSAGE(Text);
InMsg.CommitMessage();
Global vars:
MQBus:
Automation
'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter
CC2:
Automation
'Navision Communication Component version2'.CommunicationComponent
InMsg:
Automation
'Navision Communication Component version 2'.InMessage
StreamIn:
InStream
OutMsg:
Automation
'Navision Communication Component version 2'.OutMessage
StreamOut:
OutStream
Text:
Text size 1024
Comments
To have a codeunit monitor the MSMQ, you need to change it to a single instance codeunit. What I would do is to have one single instance codeunit monitoring the MSMQ and handling the received messages. Then I'd program sending the message into the form, or in its own codeunit. I don't have much time right now, but when I have some more I'll post an example in here.
RIS Plus, LLC
thanks for your reply, yes I am trying out and want to get familiar with MSMQ. If I send a message from a C++ application I get the same error!
Single instance is already set to YES otherwise I could not receive the message!
Sending the message using the function in the same codeunit as the MSMQ handling takes place is not the problem. I placed the whole code of the function SendMSMQ also in the form which containes the button but the same result!
My problem is really the error message:
The stream has returned a read error
The code I used in the event trigger comes from somewhere on the board here, so the code seems to work for other people.
Is there any way to trace this probblem more detailed? What does this error message mean? Is the stream empty oer wrong format or what?
Really tough, I cannot continue my project because of this error!
Any more ideas? Thanks!