Navision Socket Bus Adapter: Scenario

When you use the Navision Socket Bus Adapter, you have to adapt the interfaces to handle the reactions that protocols usually trigger.

In this scenario, you have designed a solution that uses Commerce Gateway, the Navision Communication Component and Navision Socket Bus Adapters to allow two products, Navision and Axapta clients, to exchange information through the Internet. You are now setting up a communication channel between the two bus adapters where the Navision client sends a document to the Axapta client.

When you test your product, you find that the receiving bus adapter doesn't close the IStream to start processing the information even though the message is in fact received in full. Since the recipient does not acknowledge the receipt, the sending bus adapter thinks that the message has not been properly received and resends the message. This loop continues almost indefinitely.

The solution is to set up the receiving interface to time out after a defined number of milliseconds and to return an acknowledgement of the receipt to the sending bus adapter. The sending bus adapter must have the CloseSendWhenWaitForReply property set to Yes, and you must ensure that the receiving bus adapter does indeed send a reply (acknowledgement).

Code Example

Your receiving bus adapter should be set up as described in the following lines of code.

First, you set up the system to receive on port 8080:

CREATE(CC2);
CREATE(SBA);
CC2.AddBusAdapter(SBA, 0);
//Wait up to 20 seconds between TCP packets
SBA.ReceivingTimeout:= 20000;
//Open port 8080 to receive data
SBA.OpenSocket(8080, '');

Your Receiving event should read the data as usual:

...
CREATE(DOM);
IF (DOM.load(InMsg.GetStream())) THEN
BEGIN
  DOM.save(txtFileName);
  IF (InMsg.ExpectReply) THEN
  BEGIN
    // Reply with the same XML as you received
    OutMsg:= InMsg.CreateReply();
    DOM.save(OutMsg.GetStream());
    OutMsg.Send(0);
  END;
END;
...

Your sending (and reply-receiving) part should be something like this:

CREATE(CC2);
CREATE(SBA);
CREATE(DOM);

CC2.AddBusAdapter(SBA, 0);
OutMsg:= CC2.CreateoutMessage('Sockets://localhost:8080');

If (DOM.load(txtFileName)) THEN
BEGIN
  DOM.save(OutMsg.GetStream());

  // Prevent waiting for the reply
  SBA.CloseSendWhenWaitForReply:= TRUE;
  InMsg:= OutMsg.SendWaitForReply(20000);
  IF (ISCLEAR(InMsg)) THEN
    ERROR(Text1000);

  DOM.load(InMsg.GetStream());
  DOM.save(txtFileName);
  InMsg.CommitMessage();
END;

where Text1000 = The message was not received.

More information:

Navision Socket Bus Adapter

Navision Socket Bus Adapter: Setting Up Interfaces

Code Example: Sending a Document

Code Example: Receiving a Document