C# talking to Navision through Messaging Queue

navnoobnavnoob Member Posts: 26
Hi all,

I have to create an app then talk to Navision through ASP.net. But before I even start, I went online and look at devguide.chm on how to speak to Navision and it seems Messaging Queue is the way to go. Anyway, I wrote a simple C# app that can send a message to Navision, but for some reason, the Navision isn't sending the message back to my C#, or my C# isn't picking up the message from the queue.

I look at the tutorial
http://msdn2.microsoft.com/en-us/library/ms952182.aspx

any try to replicate the same thing, but still my C# app isn't receiving any message.

Here is my code for the codeUnit for sending a message
CREATE(MQBus);
CREATE(CC2);
CREATE(XMLDom);

CC2.AddBusAdapter(MQBus,1);
MQBus.OpenWriteQueue('.\private$\fromNavision',0,0);
OutMsg := CC2.CreateoutMessage('Message queue://.\private$\fromNavision');
OutS := OutMsg.GetStream();
OutS.WRITE('Hello World!');
OutMsg.Send(0);

Here is my code for C# to receive the message
public MainForm()
{
mqFromNavision = new MessageQueue(".\\private$\\fromNavision");
mqFrom.Formatter = new System.Messaging.XMLMessageFormatter(new Type[] typeof(String) });

mqFromNavision.BeginReceive(new System.TimeSpan(0,0,0,30));
}

void mqFromNavision_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
{
   System.Messaging.Message m = mqFromNavision.EndReceive(e.AsyncResult);

txtReceive.Text = (string)m.Body;
}


So, what am I doing wrong? I already set the queue up as well.

Thanks

Comments

  • andreofandreof Member Posts: 133
    but for some reason, the Navision isn't sending the message back to my C#, or my C# isn't picking up the message from the queue.

    you have first to understand what is happening, and im sure you can easily see if navision is creating the message, just comment your C# code that receives messages and check the queue. Or just run the navision code manually.
    Andre Fidalgo
    My world: Dynamics NAV,SQL and .NET

    CEO at Solving Dynamics
    http://www.solvingdynamics.com
  • rvduurenrvduuren Member Posts: 92
    Try this download: http://www.mibuso.com/dlinfo.asp?FileID=593.

    It's a good example, a webservice C# ~ MSMQ ~ NAV
    Met vriendelijke groet, best regards,

    Rvduuren
  • jorgecphjorgecph Member Posts: 26
    ComCom will only recognize messages that contain the header "Navision MSMQ-BA". Now it has been some time since I did this, so I might have the wrong label. To verify this, just send a message with ComCom (and don't consume it) and see what is the label, this will be the label you will have to use to send to the queue in order for the ComCom to take up the message (again, I think it is "Navision MSMQ-BA").

    /Hope it helps
    _________________
    “This posting is provided "AS IS" with no warranties, and confers no rights.”
  • naranara Member Posts: 37
    Hi!
    I wonder if you resolved your problem?
    I am new in Navision and I had the same problem.
    I did start with the same example which you have a link too.
    Let me know if you still have the problem, may be I can help you.
  • fufikkfufikk Member Posts: 104
    Hi, all

    The article mentioned above was also a starting point for me :) Anyway, I can't remember the begining difficulties in communication, but before you run your C# program chceck if navision alone puts messages into the queue. If it does then check your program.

    Anyway, I was also given a task to create a web app which would exchange data with navision. Right now it works pretty well but I had a few design issues for which I came up with solutions and I am interested if you have any suggestions.

    1. NAS and multiple web clients. In general NAS has to satisfy requests from multiple clients, and each client has to get reposnse for their request. I came up with an idea that there is one queue for requests, which is read by NAS (1 or more). Each web client creates new message queue for responses. This way NAS reads request, processes it, sends response to appropriate queue. After client logs out, queue is destroyed.

    2. Error handling. The best solution would be to provide web client with error message that would normally be displayed to regular user. I packed functionality to separate codeunits and the only result user gets at the moment is binary - either ok or failure.

    3. Reports. Navision 3.7 had a 'runasupas' parameter which allowed for a very neat way to pass arguments to reports and get xml reponse. I guess that 4.0 only can save repors as XML to a file. Then load file to XMLDom and send it via message queue, perform encoding translation to UTF (I'm from Poland, and we have several characters which would not be displayed properly) and finally display report to web user.

    regards,

    fufikk
Sign In or Register to comment.