Software design and other ramblings RSS 2.0
# Wednesday, 06 May 2009

I recently needed to access the Label property of a remote private MSMQ through .NET. Naturally my first thought was that this should be a pretty trivial operation as this property is exposed via the MessageQueue (System.Messaging) class in the .NET framework. Unfortunately however, this property can only be read for local private queues (those on the same machine as the executing code) not for remote private queues. According to Microsoft "Private queues are registered on the local computer, not in the directory service, and their properties cannot be obtained by Message Queuing applications running on remote computers".

After a bit of testing, I found that it is possible to access remote private queue properties through .NET using DCOM. The following example shows how this can be achieved for the Label property. The same technique can be applied to retrieve other queue properties such as the Transactional state of the queue.

public static string GetRemoteQueueLabel(MessageQueue queue, string serverAddress)
{
    // Find label for remote private queue
    object queueInfoDcom = Activator.CreateInstance(Type.GetTypeFromProgID("MSMQ.MSMQQueueInfo", serverAdress));

    Type classType = queueInfoDcom.GetType();

    // Invoke method using reflection and return outputs
    BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty;

    classType.InvokeMember("FormatName", bindingFlags, null, queueInfoDcom, new object[] { queue.FormatName });

    bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod;

    classType.InvokeMember("Refresh", bindingFlags, null, queueInfoDcom, new object[] { });

    bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty;

    string label = (string)classType.InvokeMember("Label", bindingFlags, null, queueInfoDcom, new object[] { });

    return label;
}
Wednesday, 06 May 2009 20:37:55 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET | C#
Top Cashback
TopCashback
Archive
<2009 May>
SunMonTueWedThuFriSat
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017 Scott Hill

Sign In
Statistics
Total Posts: 8
This Year: 0
This Month: 0
This Week: 0
Comments: 2
All Content © 2017, Scott Hill