Click here to Skip to main content
15,867,488 members
Articles / Web Development / IIS
Tip/Trick

Verifying MSMQ is Working Fine for IIS Based Web Applications

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
22 Apr 2019CPOL 5.4K   2  
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)


Written By
Product Manager Avanza Solutions
Pakistan Pakistan
Asif embarked on his programming journey back in 1991 when he first encountered 80286 8-16 MHz systems. His programming repertoire began with dBase III+, FoxPro, C, and assembly language, where he honed exceptional skills that have been a cornerstone of his development career.

Over the years, Asif's programming saga has seen him delve into a wide array of technologies and languages, ranging from C++, VC++, Java, Delphi, RPG400, SQL Server, and Oracle, to name just a few. His insatiable curiosity continues to lead him towards newer horizons, such as DOT Net Technologies, SOA architectures, BI, DSL, and beyond. These learning experiences are underscored by a robust theoretical foundation, with a penchant for research.

Beyond the realm of technology, Asif's interests include delving into the pages of fiction, exploring biotechnology, and gazing at the wonders of Astronomy. He finds joy in watching movies, and during his free time, he delights in quality moments spent with his children.

Comments and Discussions

 
-- There are no messages in this forum --