.net communication with sockets

fufikkfufikk Member Posts: 104
Hi,

I'm trying to create an solution which allows client applications using my webserivce enter some data to Navision. I've decided to use sockets.
So in general it works (or should) like this client app sends request to webservice, it connects to navision, sends data, gets response and forwards it to the client. The webservice is written in .net c#.

the navision code unit looks like this (singleinstance=yes):
cc2 = navision comunication component
inxml = microsoft xml 3.0
OnRun()
  IF ISCLEAR(CC2) THEN
    CREATE(CC2);
  IF ISCLEAR(SBA) THEN
    CREATE(SBA);

  CC2.AddBusAdapter(SBA, 0);
  SBA.OpenSocket(8079, '');

CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
  InMsg:= InMessage;

  CREATE(inxml);
  InS := InMsg.GetStream();

  inxml.load(InS);

  DoSomeStuff.SetParam(inxml);
  result := DoSomeStuff.RUN;
  
  IF InMsg.ExpectReply THEN  
  BEGIN
    OutMsg := InMsg.CreateReply();
    OutS := OutMsg.GetStream();
    IF result THEN 
      OutS.WRITE('Y')
    ELSE 
      OutS.WRITE('N');
    OutMsg.Send(0);
  END;
  InMsg.CommitMessage();

and now the strange part:

Regular win application (c#), which connects to the navision socket directly works great. (app<->navision)
The same piece of code put into webservice, which is then consumed from another application sends data but fails on receiving. (app<->webservice<->navision)

the code for socket connection in .net looks like this:
TcpClient tcp = new TcpClient("it006nb", 8079);
			NetworkStream nw = tcp.GetStream();
			StreamWriter sw = new StreamWriter(nw);
			StreamReader sr = new StreamReader(nw);			
			sw.Write("<somexmldata>");
			sw.Flush();
			String d = sr.ReadLine();
			sr.Close();
			sw.Close();
			tcp.Close()

Anyone ever had this or similar problem? pls help

Comments

  • DenSterDenSter Member Posts: 8,307
    It is not possible to write a continuous socket connection with the SBA and the ComCom. You will have to write one yourself in C# and have it send messages into a message queue, and have a NAS monitor the queue.
  • fufikkfufikk Member Posts: 104
    I kind of solved it differently. I wrote my own component in C# which acts as the tcp server and it exposes an event with incoming message, which in my case is xml dom document. The problem I described above is gone. I'll have to run some more tests to check if it does things right since it's quite a "fresh" component O:)

    I'll post some news as soon as I get it done.

    Thanks for reply O:)
  • fufikkfufikk Member Posts: 104
    Well, I managed to get the tcp server component ready. I ran into some trouble with receiving and sending data - every few times data from/to was lost but now it's working.

    I ran one test to see how efficient this solution could be. The test environment looked like this:
    client application passed data to my webservice, which connected to my serwer component, which inserted data into navision tables.

    The data was something like a sales order: header and 2 lines. The webservice build an XmlDomDocument object from client's data and passed it to navision. Navision inserted data into header table and row table and returned a XmlDomDocument with response, which was forwarded to the client app.

    I ran it in a loop which inserted 1000 orders. The total time of this operation was about 4 minutes.

    Keep in mind that my computer (1,6mobile celeron, 521MB ram) was running client application, IIS (for webservice), NAS (8000Kb cache), Navision Database Server (20000KB cache) and some other apps (outlook, skype, etc).

    I'm curious if any one has ever tried something similar with MSMQ.

    Anyway, I think that if such solution is placed on real server machine, the performance would be much, much greater.
  • fufikkfufikk Member Posts: 104
    if you reduce the loop down to 200 orders, the test procedure completes in 20 sec. It seems that hdd is the performance killer. O:)
  • DenSterDenSter Member Posts: 8,307
    So did you write your own component that you then use as an automation server in the C/AL editor? If not and you're not using message queuing, then how else are you inserting data into Navision?
  • fufikkfufikk Member Posts: 104
    Yes, I wrote my own component. It provides one event with incoming data, just like when you use Navision's socket bus adapter and communication component 2.
  • DenSterDenSter Member Posts: 8,307
    Sounds like something we did to communicate with a warehouse system. This system only communicated through a continuous socket connection, so we wrote a service component that listens to the socket connection and sends incoming messages to a message queue, and a NAS is monitoring the queue. It's running very well, I have not heard any complaints from the customer.
  • TSESDSTSESDS Member Posts: 14
    Hi!

    We have to develop a similar scenario: many clients must request the Navision Application Server at the same time. We also want to use the Socket Bus Adapter to talk with Navision. Our current problem ist that our XML-requests have different length so it's difficult for us/the SBA to recognize the end of each request. Would you have a solution to this when using the Navision SBA? If not, we also plan to develop our own COM-object to act as a server for a socket communication. The Navision SBA seems to be very robust. The main problem with an own bus adapter is in our opinion the robustness. What if it goes down - you're in a single-instance codeunit and have no chance to re-initialize your COM-component? What experiences do you have with your own socket bus adapter?

    Thanks in advance.
Sign In or Register to comment.