.NET Framework: MSMQ

This sample shows how to send a MSMQ message from a Windows Forms client that contains a object instance serialized using XML. The messages are received and processed by a Windows Service. 

Featured Highlights

This sample has three components that work together:

Class Library

The class library, server.dll, exposes a single public class named MSMQOrders. It has 3 public fields and a method named process.

Requirements

Requires the Trial or Release version of Visual Studio .NET Professional (or greater). In addition you will need a machine that has a valid installation of MSMQ installed.

Running the Sample

Before you can run the sample three things must be done:

  1. A private queue named Orders must be created.
  2. Compile all three projects (Class Library, Client, then Service)
  3. The Windows Service must be installed.

Creating the queue varies depending upon the version of MSMQ installed. The application expects for find a private, non-transactional queue named Orders. Note you can change the queue that is expected by modifying both the client and service's configuration files.

Installing the service requires the use of a command-line tool, InstallUtil.exe, which comes with the .NET Framework SDK. To install the service do the following:

  1. Compile all three projects (Class Library, Client, Windows Service).
  2. Start the Visual Studio .NET command prompt.
  3. Changed to the bin directory of the Windows Service.
  4. Type: installutil WindowsService.exe and press Enter.

The service is configured to require MSMQ. You will need to start the service. You can do it from a command prompt by typing:

Or you can use the Windows Services MMC. To uninstall the service stop it and type the following at a Visual Studio .NET command prompt:

Note that if you decide to move the service to some other directory, you must copy the Server.dll file with it.

Once you have the service installed, run the client and send messages.

Last Update: 17 July 2002