Help with MSMQ

Hi I am having problem with MSMQ. I am able to read and write messages to MSMQ from Navision. I am trying to useC# .Net to write an application that writes to the MSMQ also, I have no problems picking up the messages from Navision, but the message is truncated. When I see the message body from MSMQ it is 3C 3F 78 6D 6C 20 76 65 72 <?xml ver 73 69 6F 6E 3D 22 31 2E 30 sion="1.0 22 3F 3E 0D 0A 3C 73 74 72 "?>…<str 69 6E 67 3E 54 65 73 74 69 ing>Testi 6E 67 3C 2F 73 74 72 69 6E ng</strin 67 3E g> but when I try to retrieve the message from Navision, the message just reads <?xml version="1.0"?> and nothing else. anyone knows what is wrong? My Navision codes are: OnRun() IF ISCLEAR(NCC2) THEN CREATE(NCC2); IF ISCLEAR(MSMQBus) THEN CREATE(MSMQBus); IF ISCLEAR(NCC2InMsg) THEN CREATE(NCC2InMsg); NCC2.AddBusAdapter(MSMQBus,3); MSMQBus.OpenReceiveQueue(‘lawrence_rig\private$\tazzy’, 0, 2); NCC2::MessageReceived(VAR InMessage : Automation “’’.IDISPATCH”) NCC2InMsg := InMessage; InStr := NCC2InMsg.GetStream(); InStr.READTEXT(str, 1000); MESSAGE(’%1’, str);

Does InStr.READTEXT reads all the text or just one line (first line in this case)? Try to use READTEXT for couple of times or use READ instead of READTEXT.

Tried using READTEXT a few times and READ also no use… it use reads the 1st line. When I tried to insert in a queue message from navision itself, like hello world, the message i got back was hello worlddddddddddddddddddddddddddddddddddddddddddddddddddddddddd… with the last char being added till the length i read the string. My Navision codes to create the queue message are: IF ISCLEAR(NCC2) THEN CREATE(NCC2); IF ISCLEAR(MSMQBus) THEN CREATE(MSMQBus); IF ISCLEAR(NCC2OutMsg) THEN CREATE(NCC2OutMsg); NCC2.AddBusAdapter(MSMQBus,3); MSMQBus.OpenWriteQueue(‘lawrence_rig\private$\tazzy’,0,2); NCC2OutMsg := NCC2.CreateoutMessage(‘Message queue://’); OutStr := NCC2OutMsg.GetStream(); OutStr.WRITETEXT(‘Hello World’); NCC2OutMsg.Send(0);

Tazzy, I ran into the problem of the repeating last character as well. The message que message needs an terminating character. I can’t remember if it was an EOF char or just a carriage return. I am trying to develop a solution for a customer us NAS and XML as well and running into similar problems with not being able to read correctly from the queue. I am following the code that is already in the system for Commerce Portal, Gateway and ADCS, it has helped alot. Any luck with your problem?

You may want to look into DVP’s Transaction Manager. It allows you to write XML which will be processed by the NAS and then XML will be returned to your application. http://www.dvp.net/

We work with DVP, then have developed solutions for at least 2 of our big customers. I’ve seen the demo on Transaction Manager. Definitely an EXCELLENT product!

FYI, I got something working here. I’m using this to put xml in the queue. I just have a form with a button that runs this codeunit whenever I want to pump an XML message in the queue. Codeunit SendXML Variables ComcomOut Automation ‘Navision Communication Component version 2’.CommunicationComponent MQBusOut Automation ‘Navision MS-Message Queue Bus Adapter’.MSMQBusAdapter XMLDOMDocument Automation ‘Microsoft XML, v3.0’.DOMDocument OutMessage Automation ‘Navision Communication Component version 2’.OutMessage OutStrm OutStream xmlout Automation ‘Microsoft XML, v3.0’.DOMDocument IF ISCLEAR(ComcomOut) THEN BEGIN CREATE(ComcomOut); IF ISCLEAR(MQBusOut) THEN CREATE(MQBusOut); NASSetup.GET; MQBusOut.OpenWriteQueue(NASSetup.“MSMQ Name - Incoming”,0,0); ComcomOut.AddBusAdapter(MQBusOut,0); END; CREATE(xmlout); OutMessage := ComcomOut.CreateoutMessage(‘Message queue://’); OutStrm := OutMessage.GetStream; xmlout.load(‘C:\NASTest\SampleXML.xml’); xmlout.save(OutStrm); OutMessage.Send(0); CLEAR(OutMessage); CLEAR(OutStrm); CLEAR(xmlout);

Then when I bring the data in I put it in a processing table. Field No. Field Name Data Type Length 1 Entry No. Integer 2 XML Doc BLOB 3 Node Name Text 250 4 Node Text Text 250 5 Node Attribute Name Text 250 6 Node Attribute Text Text 250 7 Child Node Name Text 250 8 Child Node Text Text 250 9 Child Node Attribute Name Text 250 10 Child Node Attribute Text Text 250

Finally here is the piece of code I use to loop through the xml document grabbing all the nodes and their attributes and all the child nodes of that node and their attributes Codeunit ParseXML Parameter: XMLDoc::Automation ‘Microsoft XML, v3.0’.DOMDocument Variables: Name XMLNode::Automation ‘Microsoft XML, v3.0’.IXMLDOMNode XMLNodeFound::Automation ‘Microsoft XML, v3.0’.IXMLDOMNode XMLDocIn::Automation ‘Microsoft XML, v3.0’.DOMDocument XMLProcessJrnl::Record XML Processing Journal Node::Automation ‘Microsoft XML, v3.0’.IXMLDOMNode XMLNodeList::Automation ‘Microsoft XML, v3.0’.IXMLDOMNodeList XMLChildNode::Automation ‘Microsoft XML, v3.0’.IXMLDOMNode XMLChildNodeList::Automation ‘Microsoft XML, v3.0’.IXMLDOMNodeList XMLAttributes::Automation ‘Microsoft XML, v3.0’.IXMLDOMNamedNodeMap i_child::Integer i_attribute::Integer i::Integer EntryNo::Integer Code: XMLNode := XMLDoc.documentElement; XMLNode.selectSingleNode(‘XML_NAS_TEST’); IF ISCLEAR(XMLNode) THEN BEGIN MESSAGE(‘XML_NAS_TEST Root Element Not Found!’); EXIT; END; XMLNodeList := XMLNode.childNodes; EntryNo := 0; CLEAR(XMLProcessJrnl); IF XMLProcessJrnl.FIND(’+’) THEN BEGIN EntryNo := XMLProcessJrnl.“Entry No.” + 1; CLEAR(XMLProcessJrnl); END; FOR i := 0 TO XMLNodeList.length - 1 DO BEGIN CLEAR(XMLNode); XMLNode := XMLNodeList.item(i); CLEAR(XMLProcessJrnl); EVALUATE(XMLProcessJrnl.“Node Name”,XMLNode.nodeName); XMLProcessJrnl.“Entry No.” := EntryNo; EntryNo := EntryNo + 1; XMLProcessJrnl.INSERT; CLEAR(XMLAttributes); XMLAttributes := XMLNode.attributes; FOR i_attribute := 0 TO XMLAttributes.length - 1 DO BEGIN CLEAR(XMLProcessJrnl); EVALUATE(XMLProcessJrnl.“Node Attribute Name”,XMLAttributes.item(i_attribute).nodeName); EVALUATE(XMLProcessJrnl.“Node Attribute Text”,XMLAttributes.item(i_attribute).text); XMLProcessJrnl.“Entry No.” := EntryNo; EntryNo := EntryNo + 1; XMLProcessJrnl.INSERT; END; IF XMLNode.hasChildNodes THEN BEGIN XMLChildNodeList := XMLNode.childNodes; FOR i_child := 0 TO XMLChildNodeList.length - 1 DO BEGIN XMLChildNode := XMLChildNodeList.item(i_child); CLEAR(XMLProcessJrnl); EVALUATE(XMLProcessJrnl.“Child Node Name”,XMLChildNode.nodeName); EVALUATE(XMLProcessJrnl.“Child Node Text”,XMLChildNode.text); XMLProcessJrnl.“Entry No.” := EntryNo; EntryNo := EntryNo + 1; XMLProcessJrnl.INSERT; CLEAR(XMLAttributes); XMLAttributes := XMLChildNode.attributes; FOR i_attribute := 0 TO XMLAttributes.length - 1 DO BEGIN CLEAR(XMLProcessJrnl); EVALUATE(XMLProcessJrnl.“Child Node Attribute Name”,XMLAttributes.item(i_attribute).nodeName); EVALUATE(XMLProcessJrnl.“Child Node Attribute Text”,XMLAttributes.item(i_attribute).text); XMLProcessJrnl.“Entry No.” := EntryNo; EntryNo := EntryNo + 1; XMLProcessJrnl.INSERT; END; END; END; END;

Dear James, i work for these codes below, but when i execute them an error said that theres an exception on SendwaitForReply. Have u find this problem before? Many2 thanks ------------------------------------------------------------ IF ISCLEAR(XMLDOM) THEN CREATE(XMLDOM); IF ISCLEAR(CC2) THEN CREATE(CC2); IF ISCLEAR(MQBus) THEN CREATE(MQBus); CC2.AddBusAdapter(MQBus,1); MQBus.OpenWriteQueue(QueueServer+’’+ Queue,0,0); MQBus.OpenReplyQueue(QueueServer+’’+ QueueNotify,0,0); MQBus.SenderAuthenticationLevel:= 3; OutMsg := CC2.CreateoutMessage(‘Message queue://’); OutS:=OutMsg.GetStream(); XMLDOM.load(XMLDir+SalesInvHeader.“No.”+’.xml’); XMLDOM.save(OutS); InMsg := OutMsg.SendWaitForReply(50); IF ISCLEAR(InMsg) THEN MESSAGE(‘InMsg is empty’) ELSE BEGIN InS := InMsg.GetStream; XMLDOM.load(InS); XMLDOM.save(‘1022.xml’); InMsg.CommitMessage END; CLEAR(OutMsg); CLEAR(OutS); CLEAR(XMLDOM); CLEAR(CC2); CLEAR(MQBus);