In this example, we use a single instance codeunit to:
initialize the Navision Communication Component.
establish contact with the Navision Named Pipe bus adapter.
create and send a document.
create and send a document and wait for a reply.
send an XML document using the Microsoft XML DOM.
This example does not include error handling.
For the purpose of this example, we have defined the following global variables:
Variable Name |
Data Type |
Subtype |
CC |
Automation |
'Navision Communication Component version 2'.CommunicationComponent |
NPBA |
Automation |
'Navision Named Pipe Bus Adapter'.NamedPipeBusAdapter |
OutMsg |
Automation |
'Navision Communication Component version 2'.OutMessage |
InMsg |
Automation |
'Navision Communication Component version 2'.InMessage |
Outstrm |
OutStream |
|
InStrm |
InStream |
|
Msgfile |
File |
|
FileOutStrm |
OutStream |
|
retval |
Integer |
|
Reply |
Integer |
|
ReplyMsg |
Automation |
'Navision Communication Component version 2'.InMessage |
Ch |
Char |
|
DOM |
Automation |
'Microsoft XML, v3.0'.DOMDocument30 |
We have also defined the functions Send, SendWaitForReply and SendXML.
OnRun()
IF ISCLEAR(CC) THEN
CREATE(CC);
IF ISCLEAR(NPBA) THEN
CREATE(NPBA);
CC.AddBusAdapter(NPBA, 0);
Send()
OutMsg := CC.CreateoutMessage('Named Pipe://\\.\pipe\Test');
Outstrm := OutMsg.GetStream;
Outstrm.WRITE('Hello world');
OutMsg.Send(0);
SendWaitForReply()
OutMsg := CC.CreateoutMessage('Named Pipe://\\.\pipe\Test');
Outstrm := OutMsg.GetStream;
Outstrm.WRITE('Send and wait for reply');
ReplyMsg := OutMsg.SendWaitForReply(0);
InStrm := ReplyMsg.GetStream;
Msgfile.CREATE('c:\xmlout\MsgReply.txt');
Msgfile.CREATEOUTSTREAM(FileOutStrm);
REPEAT
retval := InStrm.READ(Ch,1);
FileOutStrm.WRITE(Ch);
UNTIL retval = 0;
Msgfile.CLOSE;
ReplyMsg.CommitMessage;
SendXML()
MESSAGE('Create message.');
OutMsg := CC.CreateoutMessage('Named Pipe://\\.\pipe\Test');
MESSAGE('Message created.');
Outstrm := OutMsg.GetStream;
IF ISCLEAR(DOM) THEN
CREATE(DOM);
DOM.load('c:\xmlout\items.xml');
DOM.save('c:\xmlout\test.xml');
DOM.save(Outstrm);
OutMsg.Send(0);
CLEAR(DOM);
CC::MessageReceived(VAR InMessage : Automation)