Pending Messages in MSMQ Queue  
Author Message
Biju S Melayil





PostPosted: .NET Base Class Library, Pending Messages in MSMQ Queue Top

Hi all,

Iam using MSMQ in Windows Mobile 5.0
Mobile Application is sending the Messages(MSMQ) to the server. At some point i want to check whether any pending message is in the Queue. I tried to Access it using the following but its not returing any pending messages. I tried the same code in a windows application and its displaying the messages pending. can anyone pl tell me whether there is any error in my code.

// open the message queue
MessageQueue MQueue = new MessageQueue(QueueName);

//Initialize the MessageQueue Formatter so that the objects can serialized
System.Type[] types = new Type[1];
types[0] = typeof(ReceiptMsmq);

MQueue.Formatter = new XmlMessageFormatter(types);
try
{
TreeView1.Nodes.Clear();
TreeView1.BeginUpdate();

MessageQueue[] allprivatequeus = MessageQueue.GetPrivateQueuesByMachine(".");
foreach(MessageQueue queue in allprivatequeus)
{
TreeNode qNode = new TreeNode();
qNode.Text = queue.QueueName;
qNode.Tag = "Queue";
TreeView1.Nodes.Add(qNode);

foreach (Message m in queue)
{
TreeNode mNode = new TreeNode();
mNode.Tag = "Message";
mNode.Text = m.Label;
TreeView1.Nodes[Array.IndexOf(allprivatequeus, queue)].Nodes.Add(mNode);
}
}

TreeView1.EndUpdate();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}

// close the message queue
MQueue.Close();

This is the code iam using right now.
I just wanna display the pending messages in a tree.
Pl. help me out in this issue

Thanks In Advance
Kind Regards
Biju S Melayil



.NET Development9  
 
 
nobugz





PostPosted: .NET Base Class Library, Pending Messages in MSMQ Queue Top

MessageQueue.GetEnumerator() is marked obsolete. The Compact Framework however doesn't appear to implement GetMessageEnumerator2(). Try using GetAllMessages().


 
 
Biju S Melayil





PostPosted: .NET Base Class Library, Pending Messages in MSMQ Queue Top

Hi.

I tried using the GetAllMessages().
Still iam not able to view the Messages available in the queue.

Iam sending the part where iam sending the Message to the Queue.
Pl let me know whether am Doing anything wrong out here.

The Message is send to an Particular Static IP Server


/// <summary>
/// Message Queue Name
/// </summary>
private const string QueueName =
;

/// <summary>
/// Holds Message Queue
/// </summary>
private System.Messaging.MessageQueue mqReceipt;

mqReceipt =
MessageQueue.Create(QueueName);

private void SendMsmq()
{

try
{
this.btnSubmit.Enabled = false;

//Retrieve the IP Address of the device.
string deviceIP = string.Empty;

IPAddress[] addresses = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
for (int i = 0; i < addresses.Length; ++i)
{
IPAddress addr = addressesIdea;
if (addr.AddressFamily == AddressFamily.InterNetwork)
{
deviceIP = addr.ToString();
break;
}
}

if (deviceIP == String.Empty)
{
MessageBox.Show("Unable to retrieve Device IP");
return;
}

//Create an instance of the MessageQueue class that abstracts a
connection to a queue specified on the server
MessageQueue receiptQueue = new MessageQueue(String.Format(System.Globalization.CultureInfo
,192.168.1.1"));
// I have put this IP as Example as we arre using a different Static IP

//A recoverable message is created and the priority of the message
is set accordingly.
System.Messaging.Message message = new System.Messaging.Message(receiptMSMQ); //receiptMSMQ is declared in the beginning of the Program in Load with the Local queue Name
message.Label = receipt.receiptUniqueId;

//The response Queue is specified to receive acknowledgement from the server
message.ResponseQueue = new MessageQueue(String.Format(System.Globalization.CultureInfo
, deviceIP));
message.Priority = MessagePriority.High;
message.UseTracing = true;

// Send the Message to the Queue
receiptQueue.Send(message, String.Format(System.Globalization.CultureInfo.InvariantCulture, "Receipt Msmq ({0})", receiptMSMQ.receipt.receiptUniqueId));
}
catch (FormatException ex)
{
MessageBox.Show(ex.Message, "Conversion Error");
}
catch (System.Net.Sockets.SocketException ex)
{
MessageBox.Show(String.Format(System.Globalization.CultureInfo.CurrentCulture,"Failed to resolve Host Name:\n {0}", ex.Message));
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message, "Error sending Message");
}
finally
{
this.btnSubmit.Enabled = true;
}
}

Sorry for my Lenghty Code. Pl Let me know whether am i doing anything wrong while sending this Message in the Queue...

Kind Regards
Biju S Melayil