Reputation: 11
I cannot seem to figure out how to format the queue path. I have never used MSMQ before. I set it up, create a private queue called test, and want to try sending a message.
I am using Visual Studio, ASP.NET, webforms, C#.
protected void Page_Load(object sender, EventArgs e)
{
SendPrivateTx();
}
public void SendPrivateTx()
{
MessageQueue rmQ = new MessageQueue("jsmith528/private$/test");
rmQ.Send("message", MessageQueueTransactionType.Single);
}
This is the code I'm using. I get an error on the line after the new MessageQueue that states:
An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code
Additional information: Length cannot be less than zero.
I am sure this is the result of not having the correct path. I'm using Windows 10.
Upvotes: 0
Views: 2424
Reputation: 81
Your local private queue should be formatted as is:
@".\Private$\TextsQueue"
Here is an example of what my "StartQueue" looks like :
List<ServiceController> services = ServiceController.GetServices().ToList();
ServiceController msQue = services.Find(o => o.ServiceName == "MSMQ");
if (msQue != null)
{
if (msQue.Status == ServiceControllerStatus.Running)
{
// It is running.
//Q Creation
if (MessageQueue.Exists(@".\Private$\TextsQueue"))
{
textsQueue = new System.Messaging.MessageQueue(@".\Private$\TextsQueue");
}
else
textsQueue = MessageQueue.Create(@".\Private$\TextsQueue");
textsQueue.Purge();
textsQueue.ReceiveCompleted += new
ReceiveCompletedEventHandler(QueueReceiveCompleted);
}
Upvotes: 1