Code sample download available here
What in this post?
This post focus on:
a. Why MSMQ does not working (as it should) out of the box on compact framework
b. How to get it working
the post assume that you are familiar with MSMQ technology.
How to install MSMQ on Windows Mobile 5 device?
Operating MSMQ on Windows Mobile devices required the following files under the windows folder:
The following files should also be under windows folder (for MSMQ management)
- msmqadm.exe (command line management)
- visadm.exe (management using simple GUI)
You can copy those file to the windows folder or download the msmq.arm.CAB and
execute it on the device (the code sample does it for you).
.NET compact framework MSMQ API is subset of the .NET framework API (which having most of the .NET framework API),
and using it is straight forward if you familiar with the .NET API (the only formatter available is XML formatter).
So why doesn’t it just work?
It doesn’t working because MSMQ service should be start before you instantiate the MessageQueue.
Unfortunately the compact framework does not having API for managing the service and we need to
use PInvoke and command line execution for setting it right (you can set the service to on
the device boot but that does not functioning well and you have to check whether the service is on
in order to avoid unpleasant surprise).
Another point is that the MSMQ PInvoke has changed ,between Windows Mobile 2003 and Windows Mobile 5,
which result with none functioning code samples.
How to solve that mess?
The code sample include MSMQHelper project which is encapsulation for managing MSMQ service.
Just use MSMQServiceManager.GetCreateQueue (…) method for getting a functional MessageQueue instance.
You can also benefit from using the MSMQSetting class (exist in the code sample)
which wrap the registry entries of the MSMQ (but this is beyond the post scope).
Understanding the code sample
The code sample illustrate queue communication from compact framework device to
.NET WPF application (including acknowledging the device) while the message reach the server queue
and when the user checked the message in the UI.
It having 4 projects
- MSMQHelper (encapsulation for operating the MSMQ service on the device)
- BusinessEntities (shared objects that will be send between the client and the server)
- MSMQDesktopConsumer (WPF server implementation)
- MSMQDeviceConsumer (compact framework client implementation)
The execution flow
The flow is fairly simple:
- The server is listening for local queue incoming messages
- When ever new message arrived it present in list having checkboxs for manual acknowledge
- The client has simple input screen for sending messages
- The client will get 2 different types of acknowledge on any message it send:
– Automatic acknowledge when the message received at the server
– Manual acknowledge when the message was checked by the server side user
(the manual acknowledge will result with writing the message label into list on the client side
Point of interest
Using acknowledge over the cellular network may not operate because the cellular network
is using local IPs which not expose to the public