Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / IIS

Verifying MSMQ is Working Fine for IIS Based Web Applications

0.00/5 (No votes)
22 Apr 2019CPOL 5.9K  
Access rights issue over MSMQ could lead to hours and hours of investigation

Introduction

Recently, we faced a production issue where our web application was not able to write in our queue. Since all writing over queue is encapsulated in COM based Wrapper class which only returns Boolean in case of success or failure, it led us to hours and hours of investigation which led to nowhere. But the same wrapper class works outside of IIS (Desktop version of the application).

In order to improve investigation, we quickly built a sample web application which inserted a message into defined queue.

Image 1

The above screen creates appropriate messages in the message queue (see below).

Image 2

Using the Code

The code is extremely simple to use and by nature, self explanatory.

C#
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
    StringBuilder sb = new StringBuilder();
    try
    {
        sb.Append("btnSubmit_OnClick Called" + "<BR/>");
        System.Messaging.Message msg = new System.Messaging.Message();

        sb.AppendLine("Msg.Label => " + txtLabel.Value + "<BR/>");

        msg.Label = txtLabel.Value;

        sb.AppendLine("Msg.Body => " + txtareaBody.Value + "<BR/>");

        msg.Body = txtareaBody.Value;

        sb.AppendLine("Initiating Message Queue => " + txtQueueName.Value + "<BR/>");
        MessageQueue mq = new MessageQueue(txtQueueName.Value);

        sb.AppendLine("Message Queue Exists?" + "<BR/>");
        if (MessageQueue.Exists(mq.Path) == false)
        {
            sb.AppendLine("Message Queue not exist, aborting operation" + "<BR/>");
        }
        else
        {
            sb.AppendLine("Message Queue exist" + "<BR/>");
            sb.AppendLine("Initiating send message" + "<BR/>");
            mq.Send(msg);
            sb.AppendLine("Send Message Success" + "<BR/>");
        }
    }
    catch (Exception ex)
    {
        sb.Append(ex.ToString() + "<BR/>");
    }

    outputMessage = sb.ToString();
}

This sample application help us in identifying access issues and leads to resolution.

Points of Interest

This sample application help us in identifying access issues and leads to resolution.

History

  • 22nd April, 2019: 1.0: First version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)