Message Queue, Id and Correlation Id


Im working on a project using web services to retrieve data from Navision. It’s builit in .Net using System.Messaging on the web services side and CC2 in Navision, communicating via MSMQ. Everything works fine, requests are sent to Nav and answers come back.

The thing is that the web services will be running in many instanses using the same message queue. To make sure the correct message is read from the queue I have to be able to identify my messages from Nav and match them with the sending intance.

Having two .net apps in both ends this is a simple task: when you send a message it gets an id which you can save on the sending side. On the recieving side I use the message Id to set the Message.CorrelationId for the response message. Last, on the sending side I just wait for a message in the queue that have Correlation Id that match my send message id.

Now to my question! Can I do something similar in Nav. How do I get the messageId from a message? And can I set a correlation Id when sending a message to a queue?

If you something about this or have used another solution for the problem, please tell me.


Hi Anton,

Thanks for your respond on my question.

I did not get so far (my app is a simple “hello world”) yet to think about this issue, may be I am wrong and I misunderstood your issue.

I did tried to start and run serveral instances of my application simultaneously and every one of them worked properly, they did received right massage back from NAV.

As I said may be I am wrong, please enlighten me before I get some unpleasent problem on my project.

Hi Anton!

I’m trying to develop a very similar solution. I’m also sending Messages to an MSMQ and want to receive a reply message that correlates to the one i’ve sent.

I just don’t know how to set the Message.Id from Navision. Do you already know how to do it?

Regards, Michael

PS: You can do it with just an id (no need to use correlation), just grab the after you’ve sent the message to the queue.

I think you can’t define Message ID in NAV, You can send message ID together with message body.

Are you sure?

That would be terrible! I want to receive messeages by ReceiveById() function. That would be impossible if i couldn’t set it from NAV.

Handling several instances that send messages and need to have replies would be very difficult, if you couldn’t use ReceiveById(). It would be a very poor implementation if that wasn’t possible.

Regards, Michael

Don’t forget that NAS only processes one request at the time. If you send 10 messages Navision will only process one.

If you want to send 100 messages at the same time you must write a small Class with the concept of consumer / producer to allow your request. This concept is implemented in employee portal to support several NAS.