Accessing Outgoing Message Queues

I tried using the COM Interop Example provided in CodeProject at

But I was unable to find Microsoft Message Queue 3.0 Object Library in my Add Reference dialog. I looked online for downloading the library and found the page below. 

and it said that the mqoa.dll, mqoa20.tlb and mqoa10.tlb already exist in Windows xp. I am on Windows 7 and I was able to find these in Windows\System32. I tried registering them using the commands below:

I registered mqoa.dll using

regsvr32 “C:\Windows\System32\mqoa.dll”

I registered the tlbs using:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30139

regtlibv12.exe “C:\Windows\System32\mqoa20.tlb”

As described in

I fired up Visual Studio again but was unable to find the Microsoft Message Queue 3.0 Object Library in the COM list of Add Reference dialog.

Listing all Queues

I found the following code for listing all queues using System.Management reference. As found in

            SelectQuery q = new SelectQuery("Select * From Win32_PerfRawData_MSMQ_MSMQQueue");             ManagementObjectSearcher s = new ManagementObjectSearcher(q);             foreach (var r in s.Get())             {                 Console.WriteLine(r.Properties["Name"].Value);             }

Sample Output:











Computer Queues

The highlighted entry is an outgoing queue.

Examining a System Queue


Here’s the sample code:

            string queueName = GetQueuePath("Test", "");             MessageQueue remote = new MessageQueue(queueName);             Message testMessage = new Message             {                 Body = "test",                 UseEncryption = false,                 UseJournalQueue = true,                 UseTracing = true,                 UseDeadLetterQueue = true,                 Formatter = new XmlMessageFormatter()             };             remote.Send(testMessage);             MessageQueue monitor = new MessageQueue(queueName, QueueAccessMode.PeekAndAdmin);             Message message = monitor.Peek();             message.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });
        public static string GetQueuePath(string queue, string appServer)         {             StringBuilder queueName = new StringBuilder();             queueName.Append("FormatName:Direct=TCP:");             queueName.Append(appServer);             queueName.Append(@"\Private$\");             queueName.Append(queue);             return queueName.ToString();         }

Note that we use same queue name for the remote queue as well as monitor queue, but we create the monitor queue with QueueAccessMode.PeekAndAdmin

If we peek on the remote queue, we will get

System.Messaging.MessageQueueException: Remote computer is not available.


About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: