MSMQ on Windows Mobile 5.0

Did you know there is a new version of MSMQ for Mobile 5.0? The distribution package is available as an aditional download from here:

https://msdn.microsoft.com/mobility/windowsmobile/downloads/default.aspx

 

And finally its available through CF 2.0 on Windows Mobile 5.0.

 

Installing MSMQ requires the cab file from the redistribution download: msmq.arm.cab. Drop it on the device and run the cab to extract the driver and admin tools.

Next go and change the device name to something unique on the network (Start | Settings -> System Tab -> About ->Devic ID tab). Then go to the \windows directory and run VisAdm.exe. This provides a somewhat graphical front end to the old command line tool msmqadm.exe.

MSMQ is installed after the cab is run, but its not configured. VisAdm takes various string commands to run against the command line app. It looks a bit like this:

 

Click on the Shortcuts button to see a list of pre-populated commands and select:

1> Install (No output on success)

2> Register (a GUID is displayed, or if its already registered then you get a warning)

 

Now soft reset the device and re-run VisAdm. This time run Verify and Status to check all is working ok.

 

Right we are ready to write some code.

 

My first (and only) app simply uses a local queue to post a message and pull the same message back out of the local queue:

 

...

using System.Messaging;

namespace TestMSMQ

{

public partial class Form1 : Form

{

private void Form1_Load(object sender, EventArgs e)

{

if (!MessageQueue.Exists(@".\private$\MyQueue"))

MessageQueue.Create(@".\private$\MyQueue");

}

private void button1_Click(object sender, EventArgs e)

{

MessageQueue myQueue = new MessageQueue(@".\private$\MyQueue");

myQueue.Send(this.textBox1.Text);

myQueue.Close();

}

private void button2_Click(object sender, EventArgs e)

{

MessageQueue myQueue = new MessageQueue(@".\private$\MyQueue");

((XmlMessageFormatter)myQueue.Formatter).TargetTypes = new Type[] { typeof(string) };

try

{

Message myMessage = myQueue.Receive(new TimeSpan(0));

textBox2.Text += (string)myMessage.Body + "\r\n";

}

catch (MessageQueueException mqe)

{

MessageBox.Show("No Message");

}

finally

{

myQueue.Close();

}

}

}

}

 

Grab the whole thing from here.

There are a couple of things worth pointing out:

1> When retrieving a message from the queue the type needs to be handed to the MessageQueue class. Only string is supported at the moment.

2> It is possible to use off device queues. To do this the queue name needs to be specified as a formal name:  "FormatName:Direct=OS:MyMachine\private$\MyDesktopQueue"

3> This version of MSMQ was meant to support an HTTP transport. Unfortunately there is a bug that causes HTTP transport to fail. I believe the product team are working on this and hope to have a public fix soon. Watch this space.

 

Next I need to do something meaningful with MSMQ and a couple of devices… but that’s for another post.

 

 

Marcus