Solved

How to send message to MSMQ public queue?

Posted on 2014-12-24
3
369 Views
Last Modified: 2015-01-30
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.

  The queue does not exist or you do not have sufficient permissions to perform the operation.

   at System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath(String queuePath, Boolean throwException)
   at System.Messaging.MessageQueue.get_FormatName()
   at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Send(Object 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);
            }
        }

Open in new window


Thanks for your help
0
Comment
Question by:HPFE455
  • 2
3 Comments
 
LVL 32

Expert Comment

by:it_saige
Comment Utility
My first inclination is that the queue does not exist.

Verify that you have a Public Queue named test_queue in Computer Management -> Services and Applications -> Message Queuing -> Public Queues
Capture.JPGYour code -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
using System.IO;

namespace EE_Q28586575
{
	class Program
	{
		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);
			}
			Console.ReadLine();
		}
	}
}

Open in new window

Produces the following output for me -Capture.JPG-saige-
0
 

Author Comment

by:HPFE455
Comment Utility
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.
0
 
LVL 32

Accepted Solution

by:
it_saige earned 500 total points
Comment Utility
You can check the security properties, at a minimum you want to make sure that the ANONYMOUS LOGON has the Send Message permission.Capture.JPG

-saige-
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now