Finsql.exe version 3.60 with Hotfix 17 loaded Using ComCom2 and MSMQ Bus Adapter When streaming a message in from the MSMQ and the message does not originate from Navision (BizTalk or VBScript), the message body fails to load into a DOM. When the same message is loaded to the MSMQ from within Navision, it reads into the DOM with no problem. TIP: The message label has to be ‘Navision MSMQ-BA’ for the Receive Trigger to fire. BELOW IS THE OBJECT TO DEMONSTRATE WRITING TO A MSMQ AND PICKING THE MESSAGE UP AND LOADING TO A DOM - COPY TO A TEXT FILE IMPORT AND RUN: OBJECT Codeunit 50009 MSMQ Load XML Test { OBJECT-PROPERTIES { Date=08/26/03; Time=[ 1:02:52 AM]; Modified=Yes; Version List=NAV PIV INT; } PROPERTIES { SingleInstance=Yes; OnRun=VAR aut_ComCom2OutMsg@1000000000 : Automation “{F9A57667-8AC5-45C5-9416-99D3955BCAC0} 1.0:{6CB9762C-E61C-4F96-BA34-8B20D3A5B46E}:‘Navision Communication Component version 2’.OutMessage”; ost_DocOutStream@1000000001 : OutStream; txt_msgout@1000000002 : Text[100]; BEGIN txt_label := ‘EPROD\Private$\navtest2’; //Create Sending Objects CLEAR(aut_MQBA); CLEAR(aut_ComCom2); CREATE(aut_ComCom2); CREATE(aut_MQBA); aut_ComCom2.AddBusAdapter(aut_MQBA,0); aut_MQBA.OpenReceiveQueue(txt_label,0,0); aut_MQBA.OpenWriteQueue(txt_label,0,0); aut_ComCom2OutMsg := aut_ComCom2.CreateoutMessage(‘Message queue://’); ost_DocOutStream := aut_ComCom2OutMsg.GetStream(); txt_msgout :=’<N_CONTACT><FIRST_NAME>Carmen</FIRST_NAME></N_CONTACT>’; ost_DocOutStream.WRITETEXT(txt_msgout); aut_ComCom2OutMsg.Send(0); MESSAGE(‘Message Sent’+’ ‘+FORMAT(CURRENTDATETIME)+’ ‘+txt_msgout); END; } CODE { VAR aut_ComCom2@1000000007 : Automation “{F9A57667-8AC5-45C5-9416-99D3955BCAC0} 1.0:{01018FA5-E4B4-413C-A47C-AD34B0CC2647}:‘Navision Communication Component version 2’.CommunicationComponent” WITHEVENTS; aut_ComCom2OutMsg@1000000008 : Automation “{F9A57667-8AC5-45C5-9416-99D3955BCAC0} 1.0:{6CB9762C-E61C-4F96-BA34-8B20D3A5B46E}:‘Navision Communication Component version 2’.OutMessage”; aut_ComCom2InMsg@1000000016 : Automation “{F9A57667-8AC5-45C5-9416-99D3955BCAC0} 1.0:{D184D0AC-61C9-4AC1-B537-0D28C277FEDE}:‘Navision Communication Component version 2’.InMessage”; aut_MQBA@1000000006 : Automation “{B8BD635A-E191-47EF-84A0-02921E2A44A6} 1.0:{CD49794B-0E84-4A2E-9522-C518C825D390}:‘Navision MS-Message Queue Bus Adapter’.MSMQBusAdapter” WITHEVENTS; txt_msg@1000000014 : Text[1024]; txt_label@1000000018 : Text[100]; EVENT aut_ComCom2@1000000007::MessageReceived@1(VAR InMessage@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:’’.IDISPATCH"); VAR XMLDocIn@1000000003 : Automation “{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:‘Microsoft XML, v3.0’.DOMDocument”; ist_DocInStream@1000000001 : InStream; BEGIN //Open and Receive Stream MESSAGE(‘Message Received’+’ '+FORMAT(CURRENTDATETIME)); CLEAR(XMLDocIn); CREATE(XMLDocIn); aut_ComCom2InMsg := InMessage; ist_DocInStream := aut_ComCom2InMsg.GetStream(); IF XMLDocIn.load(ist_DocInStream) THEN BEGIN aut_ComCom2InMsg.CommitMessage(); MESSAGE(‘Success’+FORMAT(XMLDocIn.xml)) END ELSE MESSAGE(‘Failure’); END; BEGIN END. } }
Hi Lindsay, I am trying to do basically the same thing, except my IS dept. has chosen to use the socket bus adapter. We are going to use Navision 3.7 and have BizTalk 2002 send it the message (Simple XML doc). I have set up the code according to your specifications and have also tried other example code without success. In code unit 7700 I enterrd the following code. OnRun() IF ISCLEAR(SBA) THEN BEGIN CREATE(SBA); //SBA.HTTPHeaderReceive := TRUE; SBA.OpenSocket(8079, ‘’); END; IF ISCLEAR(CC2) THEN BEGIN CREATE(CC2); CC2.AddBusAdapter(SBA, 0); END; CC2::MessageReceived(VAR InMessage : Automation “’’.IDISPATCH”) BEGIN //Open and Receive Stream MESSAGE(‘Message Received’+’ '+FORMAT(CURRENTDATETIME)); CLEAR(XMLDocIn); CREATE(XMLDocIn); InMsg := InMessage; InS := InMsg.GetStream(); IF XMLDocIn.load(InS) THEN BEGIN InMsg.CommitMessage(); MESSAGE(‘Success’+FORMAT(XMLDocIn.xml)) END ELSE MESSAGE(‘Failure’); END; When I get to setting the InStream object (InS := InMsg.GetStream();), “InS” does not get a value assigned, which I assume is the real problem. When I try to use the Instream object (XMLDocIn.load(InS)), I recieve the error, “The stream has returned a read error”. Not very helpful :(. I am running Navision 3.7 in SQL, no Hotfixes. I am sending the message to Navision using BizTalk 2002. The XML is a very small simple document(ex. Hello). Any help would be greatly appeciated. -Robert
Hi Robert, Instead of : InS := InMsg.GetStream(); IF XMLDocIn.load(InS) Try: IF XMLDocIn.load(InMsg.GetStream()); Sometimes this makes a difference. FYI the sample that you referenced is what I was using that did NOT work. After spending about four days on the phone with Microsoft, I eventually abandoned trying to receive the message using the MQBA and used the Commerce Portal MSMQ component. There is a formatting issue related to UTF 8 vs UTF 16. Scripting a MSMQ message formatted it to UTF 16 and the Navision message sink could only interpret UTF 8. You can tell the difference by looking at the MSMQ message body. In UTF 16 there is a space between each character in the message. I don’t know if this is an issue with the Sockets BA. Hope this helps. L
Hi Lindsay. Thank you for the tip. What I found is that by using the Socket Bus Adapter, I needed to set the ReceiveTimeout property to a value greater than 0 in order to get the full message. I found that 5000 (5 seconds) was sufficient for small to medium sized messages. One of two problems I am still struggling with is how to remove the http header form the message coming in. Since I am sending the mesage to a port (ex. 8085) using an http request from BizTalk, the header is attached to the mesage, and therefore does not allow me to load the actaul XML into a DOM object. I tried setting the property HTTPHeaderReceive to False, but that does not appear to do anything to the header. I am considering writing a Com object to pull in the stream and and strip out the header and then pass it back to Navision as just XML. Do you know of any way to use Navsions objects to do this? The second problem is that BizTalk is waiting for a http response acknowledging that the message was received. I do not see any built in way to do this either. Navision Communication components “reply” features appear to only be directed to systems that both use Nav Com 2. My thought is to create a response header dynamically and send it back in the Out message stream. Again any thoughts on this are welcome. Thanks again for your help. -Robert
You are right, an HTTP Post will send headers and I don’t think there is any way to strip them off. As for a reply, there is no facility to do that in using the Sockets BA. If you can determine what kind of reply it is looking for, I’m sure you could construct one (you would need to know the IP, port and HTTP message it was looking for) The HTTP response it is looking for would be generated by a web server (The BizTalk HTTP post is used to post a file to an ASP or other web page). You could determine what message you would need for a reply by generating an ASP page, having Biztalk post to the ASP page and then examining the weblog to see how the Web server constructed the HTTP reply. As an alternative (if you are determined to use sockets) you could stream the Post into a BLOB, stream the BLOB out to text, strip the headers off and then stream the Text back into an XML object. I ran into this same HTTP Post problem when trying to integrate Biztalk and Pivotal. I still recommend you use MSMQ because of it’s simplicity (you would not have to write a COM component). Outbound the BA works great, inbound, the Commerce Portal MSMQ component works best. Lindsay
Ah yes. We are certainly on the same page on this one. I was able to trip the header out in Navision. I basically created a function that found the begining of the XML doc and then read the rest of the InStream into another stream and loaded that into a DOM object. I did create a asp.net page that recieves the HTTP post from BizTalk. I then used Ethereal (free download) to watch the traffic on my PC to see the incoming and outgoing request/responses. FYI- add the filter "ip host " if you try this product, or else you will pick all the net work traffic, yuck! Anyway, I did my best to reconstruct the header. Here is good site to get an understanding of this: http://www.perlfect.com/articles/http.shtml No luck on the response so far, but I will keep it on the back burner for now. I am having my solution center check in with Microsoft (Navision) on a possible fix/solution for the future. If they could add this feature to the SBA that would make BizTalk implementations ideal. I wouldn’t have to monitor the message queues and I could have BizTalk handle all the connection and failed document errors. So, for the time being I will resort to the message queues. As I get deeper into it I am finding that Navision Com 2 does not support transactional queues. Again another disappointment. BizTalk by nature wants you to use transactional queues when you have an N-Tiered envirnoment. In a larger organization such as ours, it is not feasible to have our NAS running on our BizTalk server. Have you had any problems with this? Should I be watching the “nsadminreceivequeue” queue for errors? What is that queue used for anyway? How do I let BizTalk know everyting is “A-OK”? The documentation on this is somewhat limited. Sorry for all the questions, but I really want to get a handle on this. Not top be to critical, but this all appears to be a little “half-baked” and not ideal for larger enterprises. I will try to make the best of what I got. Thank you once again for your exceptional input. -Robert