?
Solved

How to send message to MSMQ public queue?

Posted on 2014-12-24
3
Medium Priority
?
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 40517008
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
ID: 40517018
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 34

Accepted Solution

by:
it_saige earned 1500 total points
ID: 40517033
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

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