HPFE455
asked on
How to send message to MSMQ public queue?
I have created a public queue in MSMQ. When I am trying to write/read messages to the queue, my application is throwing the below error.
My code is:
Thanks for your help
The queue does not exist or you do not have sufficient permissions to perform the operation.
at System.Messaging.MessageQueue.Resolv eFormatNam eFromQueue Path(Strin g queuePath, Boolean throwException)
at System.Messaging.MessageQueue.get_Fo rmatName()
at System.Messaging.MessageQueue.SendIn ternal(Obj ect obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionTyp e transactionType)
at System.Messaging.MessageQueue.Send(O bject obj)
My code is:
private static string queueName = @".\test_queue";
static void Main(string[] args)
{
try
{
MessageQueue msgQ = new MessageQueue(queueName);
string sMessage = "Test MSMQ Message 2";
msgQ.Send(sMessage.Trim());
System.Messaging.Message[] MSMQMessages = msgQ.GetAllMessages();
foreach (System.Messaging.Message msg in MSMQMessages)
{
byte[] data = new byte[1024];
msg.BodyStream.Read(data, 0, 1024);
string strMessage = ASCIIEncoding.ASCII.GetString(data);
Console.WriteLine(strMessage.Trim());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Thanks for your help
ASKER
Thanks saige. I have checked the queue and it exists. (Actually I have created the queue). Now I think my login may not have enough privileges to read and write messages to the queue.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Verify that you have a Public Queue named test_queue in Computer Management -> Services and Applications -> Message Queuing -> Public Queues
Your code -
Open in new window
Produces the following output for me --saige-