Infosys Microsoft Alliance and Solutions blog

« Software Factory: Towards the Holy Grail of Software Development | Main | Software Factory: Adopting DSM for High Evolvement Systems »

MSMQ - Receiving messages from remote private queues

Sometime back I had blogged about how to send messages to remote private queues. There were a few queries on how to read from remote queue as well.

To me it should have worked by using the MessageQueue.Receive API instead of .Send. I decided to give this a try anyway and it indeed is as trivial as that. However a few things to take care while trying to get this working.

1. Check the documentation to see where all the API works. The API may have limitations in working in workgroup mode if you are not using the direct format name syntax.

2. The other very important aspect is setting the formatter prior to receiving the message. You need to set this appropriately to binary or XML and specific type to ensure successful read.

To show a complete example, find below code that posts to the remote queue (transactional as well as non-transactional) and also reads from them. To keep things simple, I have used a simple string message here. However you can definitely use more complex types and custom types for sending and receiving (as long as they match both ways).

        private void btnPostToQueue_Click(object sender, EventArgs e)


            //post to regular non-transactional remote queue using OS name

            MessageQueue rmQ = new MessageQueue("FormatName:Direct=OS:punhjw30076\\private$\\remote");

            rmQ.Send("sent to regular queue - Atul");


            //post to  transactional remote queue using IP address

            MessageQueue rmTxnQ = new MessageQueue("FormatName:Direct=TCP:\\private$\\remoteTxn");

            rmTxnQ.Send("sent to transacted queue - Atul", MessageQueueTransactionType.Single);



        private void btnGetFromQueue_Click(object sender, EventArgs e)


            //retrieve from regular non-transactional remote queue using OS name

            MessageQueue rmQ = new MessageQueue("FormatName:Direct=OS:punhjw30076\\private$\\remote");

            rmQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });

            System.Messaging.Message msg = rmQ.Receive();



            //retrieve from transactional remote queue using IP address

            MessageQueue rmTxnQ = new MessageQueue("FormatName:Direct=TCP:\\private$\\remoteTxn");

            rmTxnQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });

            System.Messaging.Message msgTxn = rmTxnQ.Receive(MessageQueueTransactionType.Single);



Hope this helps !


Atul, Much appreciated article, recently, very recently I've been trying to do this... ended up with error. good work.

Mahesh: Glad you found it useful

Could not read from remote queue. Because it was not able to find remote computer using direct format over http or os. I am able to send message to same remote queue using direct format name http.

@Kobita, ideally the same convention should work for both send and receive. I hope you had checked the basic things like the server is up and running and using transactions if it is a transactional queue.

Another important aspect when receiving message is the right formatter to be used to read the message.

Atul, this article was very useful. Good work - simple and precise!

@Raj, thanks.

Hi: I'm using the same code to receive a message from MSMQ Server in other domain and got an error "MessageQueueErrorCode -2147023071 System.Messaging.MessageQueueErrorCode" can anybody help me ?

@Juan, did you capture the error correctly? Check here for the details around MessageQueueErrorCode enumeration -

The values of the enumeration can be found here -

I used the exact command listed in the previous posts, but in vain.

Basically, I want to send a message to a remote private queue. On debug, no error occured and the message seems to have been successful.

However, I can still see it in the outgoing queue on the local machine as if it was being blocked somehow.

Here is the command I use : MessageQueue Queue = new System.Messaging.MessageQueue("FormatName:Direct=OS:wmqdev\\private$\\filesar").

That should work, should it not?

Moreover, the status "Department" is "connected" and the IP address also matches.

I also used this command with the IP address of the remote machine (FormatName:Direct=TCP:.......\\private$\\filesar) but it didn't solve the problem either.

I have been looking for the solution for days. Nevertheless, can't get my head around it.

If someone could help me out!

P.S.:I am using the C# programming language .NET framework 1.1

Thank you very much.

Youss, not sure what is "Department". From the code it looks like your remote machine name is "wmqdev". Can you ensure that this remote machine is up and running and that MSMQ Service is also running on that machine.

Also do verify that Everyone has write access to the queue (filesar) or atleast the write access is provided to the ID from which you are trying to write to the queue.

Displayed an error as Remote server is not available.

I followed steps to receive msg from remote MSmq but am getting the following error :
The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted.

hi ,
please can somebody help me in this regard .
we have transactional private queue which has no of msgs situated on machine A , i just want to receive messages from machine A 's private transactional queue to machine B using windows service . i am continiously getting following error
"The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted."
Atul help on this issue will be appriciated .
please let me know !!!!!!!!!

Rashmi, can you post the code here about how you are trying to receving the message from the remote queue? The error you have mentioned means an incorrect naming of the remote queue. Else, feel free to send me the code at atulg AT infosys DOT com

code is as follows
oQueuePath = new StringBuilder(@"FormatName:Direct=OS:chintan\Private$\interfacelogqueue");
m_oListener = new MSMQListener(oQueuePath.ToString());
m_oListener.FormatterTypes = new Type[] { typeof(String) };
m_oQueue.Formatter = new XmlMessageFormatter(m_arrTypes);
m_oQueue.Formatter = new XmlMessageFormatter(m_arrTypes);
m_oQueue.PeekCompleted += new PeekCompletedEventHandler(OnPeekCompleted);

m_oQueue.ReceiveCompleted += new ReceiveCompletedEventHandler(OnReceiveCompleted);

now ,
method onpeekcompleted

oTran = new MessageQueueTransaction();

oMessage = m_oQueue.Receive(MessageQueueTransactionType.Single);

hi atul,
the exact lines where i am getting problem is
if (m_oQueue.Transactional) {
else {
if condition itself it cant support direct format ,
any suggestions ?

Rashmi, you are getting the error since you are calling the Transactional property which is not available for remote queues. See here for details -

In your case, since you know which queue you are polling, you will also know if it is transactional or not and you need to directly use that knowledge in the code.

I have an application, where i open the private Queue. This works fine.
But when I run this app as a windows service, it gives an error- failed to open the Queue, Access is denied.

I know it has something to do with the rights.

If the app is run as an exe, it will have the log on credentials. When run as windows service it will run with System credentials, which may not have access to Private Queue.

How do i enable my windows service to have access to the private Queue???

Any help will be great.

From your computer management console, you can view queue properties and give it appropriate rights. Verify which identity is the windows service using and then give write rights to this same identity for the queue

I am also getting the same error.
"The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted."

Code Snippet:
MessageQueue MyMessageQ = new MessageQueue(@"FormatName:Direct=OS:Corp-0253\private$\PQ");

Putting the breakpoint on above statement, and watching the properties of MyMessageQ shows most of the properties filled with error above.

In this way I am able to send a message but receiving causes the above problem.

Queue is non transactional and permission to everyone and anonymous user.

Any help would be appreciated.

Lalit, when receiving you need to also specify a formatter to receive the message. hope you are doing that as well.

Hi Atul,

If I have the below environment setup, do I need to install MSMQ even on Win Server B which is suppose to do a remote read/write from Win Server A using BizTalk MSMQ adapter.

Windows Sevrer A: I would have the Application and the MSMQ installed and on
Windows Server B: I would have BizTalk Server 2006 installed which also has the MSMQ adapter installed along with it

Please do reply. Thanks.

Howard, Yes. The OS needs to have the basic infrastructure for MSMQ configured

i want to read from the remote queue which is at windows server 2008 and that is in different domain.
Is it possible to read from the queue , if yes please send me the queue connection format like Direct Name...

Pawan, different domain will typically mean you need to work with public queues. I haven't worked on them, and at this time I don't have the bandwidth to research on it. Regret that I can't provide much help.

I am trying to read from remote private queue that is installed on Windows 2003 server OS. My machine's OS is Windows XP. My HKLM\SOFTWARE\Microsoft\MSMQ\Parameters\CurrentBuild has 5.1.1111 value which indicates I am using MSMQ 3.0 on Windows XP. Can I read from remote private queues in this case?

Please Describe me how can i host msmq service for msmqintegration on iis 7.0

I want to read the MSMQ where queue data in byte and numbers of queues generated in 1 mins about 1500.

If read continuously queue, cpu goes on 30%, and after some time it stopped.
I need to read queue in high volume upto 4 hrs.

I want safe thread reading in such a manner that shouldn't be blocked.
Actually I am not good about threading so can you please help me out?

Currently I am reading in this manner:

bool ProcessStatus; //process
Thread _UDPthreadConsme;

private void btn_receive_Click(object sender, EventArgs e)

if (MessageQueue.Exists(@".\private$\myquelocal"))

ThreadStart _processrcs = new ThreadStart(receivemessages);
_UDPthreadConsme = new Thread(_processrcs);
ProcessStatus = true;

private void receivemessages()
while (ProcessStatus)

// Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(@".\private$\myquelocal");

System.Messaging.Message[] myMessagecount = myQueue.GetAllMessages();

if (myMessagecount.Length <= 0)

myQueue.Formatter = new BinaryMessageFormatter();

// Receive and format the message.
System.Messaging.Message myMessage = myQueue.Receive();
byte[] buffer = (byte[])myMessage.Body;

// here i convert buffer to its related structure and then insert the values in database sqlserver.


@Amit, @Aishraj, I am no longer working with MSMQ and my current bandwidth does not allows me investigate further.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter