MSMQ COM API in C#
Asked Answered
P

2

13

What is the best way to use MSMQManagement from C#? I need the ability to peek and purge a local outgoing queue when the remote machine is disconnected.

Apparently some users can do this through the COM API, but in the COM References tab, I don't have the "Microsoft Message Queue 3.0 Object Library" that other websites/blogs/postings mention (nor anything remotely similar). I've searched the machine for Interop.MSMQ.dll and cannot find it either.

We are using VS 2008 and running on Windows 7 64-bit.

What am I missing? Are there other mechanisms to accomplish this through "normal" managed classes?

Thanks

Patchouli answered 22/11, 2011 at 22:27 Comment(3)
If you do not have MSMQ installed in your Windows 7 machine, go to Control Panel -> Programs and Features and add the Feature MS MQ...Disobey
MSMQ is installed, as is the DCOM Proxy. I can use "normal" features of MSMQ without problem via the System.Messaging class. What I cannot do is purge or peek messages in a local outgoing queue when the machine on the other end of the queue is disconnected from the network. Either of these operations will throw a MessageQueueException when the machines are not connected.Patchouli
There are loads of examples on the web of other developers using the COM API to access an MSMQManagement class, via managed code, which is not contained in System.Messaging. These examples demonstrate adding a reference to the "Microsoft Message Queue 3.0 Object Library" via the COM references tab. I do not have this selection. I'm looking for a way to get this DLL, or to at least find out that it won't work on Windows 7/Server 2008.Patchouli
H
21

Project + Add Reference, Browse tab. Navigate to c:\windows\system32 (or syswow64 on a 64-bit operating system) and select mqoa30.tlb. This creates the Interop.MSMQ.dll interop assembly you are looking for. Beware that MSMQ is an optional Windows component, you'll need to install it first if the file isn't present on your machine.

Homogenetic answered 24/11, 2011 at 14:54 Comment(4)
This does not seem to work (at least not in Visual Studio 2010). I get this error: "Could not load file or assembly 'mqoa30.tlb' or one of its dependencies. The module was expected to contain an assembly manifest. This file may not be a managed assembly."Dede
I've confirmed that this works in Visual Studio 2008 and not in Visual Studio 2010. I asked a question about it here: #9594038Dede
Works just fine when I try it in VS2010. You are not using the Browse tab, I don't recognize the screen shot.Homogenetic
I was using Microsoft's "Productivity Power Tools" (visualstudiogallery.msdn.microsoft.com/…). I guess that power tool does not allow Type Libraries. I disabled it and I was able to add the reference just fine.Dede
D
3

you can use it natively from .NET by using: System.Messaging.MessageQueue

check these articles:

Accessing Message Queues

Reliable Messaging with MSMQ and .NET

Disobey answered 22/11, 2011 at 22:29 Comment(2)
System.Messaging is different from the COM API library. System.Messaging does not allow access to the local outgoing queue (unless it's on the same machine as the other end). The MSMQManagement class provides some mechanisms to do this, but I cannot figure out how to access it via managed code.Patchouli
Just as a note, the C# version is also missing the possibility to send the same message to multiple queues (see MSMQDestination COM object)Vandiver

© 2022 - 2024 — McMap. All rights reserved.