none
How to write C#/WPF/WCF client to display and delete entries in MSMQ RRS feed

  • Question

  • I modified the server source code at https://www.codeproject.com/Articles/326909/Creating-a-WCF-Service-with-MSMQ-Communication-and to execute CMD.EXE commands and implemented a WCF throttle so that only one queue entry is executed at a time.

    How can I enhance the following code to fetch my pending queue entries and display the CMD.EXE command in a WPF list box so I can delete a queue entry that has not been removed from the queue yet by the server. Linqpad is giving me the XmlExecption "Invalid character in the given encoding. Line 1 postion 57". 

    After I display all the queue entries and select one, how do I delete an entry?

    Thanks

    Siegfried

    System.Messaging.MessageQueue[] queueList = System.Messaging.MessageQueue.GetPrivateQueuesByMachine(Environment.MachineName);
    //queueList.Dump();
    var q = queueList[0];
    q.QueueName.Dump();
    q.CanRead.Dump();
    var e = q.GetMessageEnumerator2();
    while (e.MoveNext())
    {
    	var mes = e.Current;
    	mes.Formatter = new System.Messaging.XmlMessageFormatter(new Type[]	{typeof(string)});
    //	XmlMessageFormatter(new string[] { "System.String,mscorlib" });
    	mes.Body.ToString().Dump();
    }


    siegfried heintze

    Sunday, March 12, 2017 11:15 PM

Answers

  • Hi,

    In general, a queue entry will be removed when it has been received by the server. Could you share us how did you check whether the queue entry has been removed or not? If you follow Computer Management->Services and Applications->Message Queuing->Private Queues, you need to refresh by right click the Private Queues.

    For removing queue entry, I suggest you try below code:

                System.Messaging.MessageQueue[] queueList = System.Messaging.MessageQueue.GetPrivateQueuesByMachine(Environment.MachineName);
                MessageQueue myQueue = queueList[0];
                MessageEnumerator enumerator = myQueue.GetMessageEnumerator2();
                while (enumerator.MoveNext())
                {
                   enumerator.RemoveCurrent();
                }

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 13, 2017 2:13 AM

All replies

  • Hi,

    In general, a queue entry will be removed when it has been received by the server. Could you share us how did you check whether the queue entry has been removed or not? If you follow Computer Management->Services and Applications->Message Queuing->Private Queues, you need to refresh by right click the Private Queues.

    For removing queue entry, I suggest you try below code:

                System.Messaging.MessageQueue[] queueList = System.Messaging.MessageQueue.GetPrivateQueuesByMachine(Environment.MachineName);
                MessageQueue myQueue = queueList[0];
                MessageEnumerator enumerator = myQueue.GetMessageEnumerator2();
                while (enumerator.MoveNext())
                {
                   enumerator.RemoveCurrent();
                }

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 13, 2017 2:13 AM
  • Actually, I had not considered checking whether the queue entry had been moved. I supposed the GUI would poll the list of queue entries once a second?

    Thank you for the "RemoveCurrent" function call.

    Now for my remaining question: when my GUI client calls my WCF server with a function call, it passes several strings including the CMD.exe command as function arguments.  How can I enumerate the queue and extract this string argument so I can display it in a WCF list box or list control?

    thanks

    Siegfried


    siegfried heintze

    Monday, March 13, 2017 2:44 AM
  • >>when my GUI client calls my WCF server with a function call, it passes several strings including the CMD.exe command as function arguments.  How can I enumerate the queue and extract this string argument so I can display it in a WCF list box or list control?

    For this new issue, I would suggest you post a new thread, and share us more information about what you mean by "How can I enumerate the queue and extract this string argument so I can display it in a WCF list box or list control". What string argument do you want?


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 13, 2017 3:08 AM