Search code examples
c#.netmessage-queuemsmqsendmessage

C# MSMQ MessageQueue Id - How to get Valid Guid


I tried to send a message in a Local Queue as well as in the Remote Queue.

The Sample Source is

Guid queueId;

try
{
    MessageQueue rmQ = new MessageQueue("FormatName:Direct=TCP:192.168.5.26\\Private$\\RemoteQueue");
    //MessageQueue rmQ = new MessageQueue(".\\Private$\\LocalQueue");
    rmQ.Send("Once again Mr.John Please come here...");

    queueId = rmQ.Id;
}
catch (ArgumentException ex)
{
    throw ex;
}
catch (MessageQueueException ex)
{
    throw ex;
}
catch (InvalidOperationException ex)
{
    throw ex;
}
catch (Exception ex)
{
    throw ex;
}

In all the Scenario I am getting Guid.Empy but the message is queuing successfully in the respective machine's Message Queue.

Kindly review the following snapshot

enter image description here

Kindly assist me how to get the Valid MessageQueue.Id


Solution

  • You are trying to access an ID of a private queue, which is unsupported. MSDN says:

    Message Queuing sets the Id property when it creates the queue. This property is only available for public queues.

    See

    https://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.id(v=vs.110).aspx