Have you ever needed to make Web requests to Navision? Often you then would be using either NAS or a 3’rd part product to handle these requests. Why not build your own handler 😉
All you have to do is take advantage of the automations “Navision Communication Component version 2” and “‘Navision Socket Bus Adapter”.
Let’s take it step wise.
First you have to open a connection to a socket.
IF ISCLEAR(CommComponent) THEN
IF ISCLEAR(SocketBusAdapter) THEN
SocketBusAdapter.OpenSocket(Port, ”); //Port = 80 if listening for standard http
Where CommComponent is
…..‘Navision Communication Component version 2’.CommunicationComponent
and SocketBusAdapter is
…..‘Navision Socket Bus Adapter’.SocketBusAdapter
On the CommComponent variable, set the property WithEvents to yes. A new function appears by enabling this property (CommComponent::MessageReceived). This gives us the possibility to react when a message is received.
Messages, that a received from a socket must be streamed.
//Read received data from socket
CCInMsg := InMessage;
Where CCInMsg is ‘Navision Communication Component version 2’.InMessage
and InStreamMsg is InStream and Message is a simple Text variable.
When you first have the read the received data from the socket, you can act according to the received order / data and the create and send a response back. This is done by using a stream.
OutMsg := InMsg.CreateReply;
OutStreamMsg := OutMsg.GetStream();
IF Message <> ” THEN
Where OutMsg is a ‘Navision Communication Component version 2’.OutMessage and
OutStreamMsg is a outstream.
Remember, when creating the codeunit, to set the SingleInstance property to Yes. If the SingleInstance property is not set, the Codeunit will not be listening for CommComponent Events.
That’s mainly what there is to do – now you have built your own port listener in Navision 🙂