Options

MSMQ example does not work!?!

dr.burnsdr.burns Member Posts: 6
Hello,

I try to get the example from:

http://msdn.microsoft.com/library/defau ... vision.asp

to work, but I get two error messages:
CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH") 
// get the message 
InMsg := InMessage; 
InS := InMsg.GetStream(); 

// load the message into an XML document and find a node 
XMLDom.load (InS); // <-- 1st ERROR 
XMLNode := XMLDom.selectSingleNode ('string'); 

// open the response queue and create a new message 
MQBus.OpenWriteQueue('.\fromNavision',0,0); 
OutMsg := CC2.CreateoutMessage('Message queue://.\fromNavision'); 
OutS := OutMsg.GetStream(); 

// build the contents of your message 
XMLNode.text := UPPERCASE (XMLNode.text); 

// fill the message and send it 
OutS.WRITE(XMLDom.xml); // <-- 2nd ERROR 
OutMsg.Send(0); 


The 1st error message I get is:

'The stream has returned a read error'

followed by

'This Automation variable has not been instantiated. You can instantiate it by either creating or assigning it'

If I replace the line:

XMLDom.load (InS); by: XMLDom.load (InMsg.GetStream());

it works. So why does this happen in example code from Microsoft?


The 2nd problem I cannot solve is that the error message:

'This Automation variable has not been instantiated. You can instantiate it by either creating or assigning it'

comes up at a different line also!
I run the debugger and everything works fine until following line:

OutS.WRITE(XMLDom.xml);

But I just copied the example code from the Microsoft site!
Does anybody have an idea whats going wrong?

I already instanitated the vars in the OnRun triger of my codeunit as mentioned under the MS example.

Any help would be highly appreciated! Thanks in advance!

dr.burns

Comments

  • Options
    DenSterDenSter Member Posts: 8,304
    The error comes from the fact that you have not instantiated the XMLDom object. Try adding the following at the beginning of the event, before any other reference to the XMLDom object:
    IF NOT ISCLEAR(XMLDom) THEN
      CLEAR(XMLDom);
    CREATE(XMLDom);
    
    After you added this, the XMLDom.load(InS) should work.

    I don't know why else the Instream stuff would be erroring out on you. If it is still erroring out on you, check the variable types. The InMsg should be a 'Navision Communication Component version 2'.InMessage object, and the Ins variable should be an InStream variable.

    Then, to load the xml into the outstream, instead of
    OutS.WRITE(XMLDom.xml);
    OutMsg.Send(0);
    
    you do this:
    XMLDom.save(OutS);
    OutMsg.Send(0);
    

    I don't know if your other XML code will work though, as your XMLNode isn't loaded back into your XMLDom object. I haven't tested it the way you wrote this. You can check the standard Navision Biztalk codeunits for great examples of XML document building.
Sign In or Register to comment.