Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to send message to MSMQ public queue?

Posted on 2014-12-24
3
Medium Priority
?
645 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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