The Navision Named Pipe Bus Adapter - Server Side Code Example

In this example, we use a single instance codeunit to

For the purpose of this example, we have defined the following global variables:

Variable Name

Data Type

Subtype

ComCom

Automation

'Navision Communication Component version 2'.CommunicationComponent

NPBA

Automation

'Navision Named Pipe Bus Adapter'.NamePipeBusAdapter

InMsg

Automation

'Navision Communication Component version 2'.InMessage

ReplyMsg

Automation

'Navision Communication Component version 2'.OutMessage

DOM

Automation

'Microsoft XML, v3.0'.DOMDocument30

InStrm

InStream

 

MsgFile

File

 

OutStrm

OutStream

 

retval

Integer

 

Reply

Integer

 

FileOutStrm

OutStream

 

Ch

Char

 

Example

OnRun()

IF ISCLEAR(ComCom) THEN

  CREATE(ComCom);

IF ISCLEAR(NPBA) THEN

  CREATE(NPBA);

ComCom.AddBusAdapter(NPBA, 0);

NPBA.OpenNamedPipe('Test', 0, 0);

ComCom::MessageReceived(VAR InMessage : Automation)

MESSAGE('Message received.');

InMsg := InMessage;

InStrm := InMsg.GetStream;

CREATE(DOM);

DOM.load(InStrm);

MESSAGE('DOM loaded.');

MsgFile.CREATE('c:\xmlout\MsgFile.txt');

MsgFile.CREATEOUTSTREAM(FileOutStrm);

REPEAT

  retval := InStrm.READ(Ch,1);

  FileOutStrm.WRITE(Ch);

UNTIL retval = 0;

MsgFile.CLOSE;

Reply := InMsg.ExpectReply;

IF Reply <> 0 THEN

BEGIN

  ReplyMsg := InMsg.CreateReply;

  OutStrm := ReplyMsg.GetStream;

  OutStrm.WRITE('Reply message');

  ReplyMsg.Send(0);

END;

InMsg.CommitMessage;