Freigeben über


Queued Components Technology Sample

This sample demonstrates the interaction of .NET applications with Microsoft Message Queuing (MSMQ) technology and with the Queued Components feature of COM+. MSMQ allows applications to communicate across networks and systems that may be temporarily offline. Messages generated by sending applications are stored in queues so they can be retrieved later by receiving applications. Queued Components builds on MSMQ to provide asynchronous invocation and execution of server components.

NoteImportant

To build and execute this sample, you must have MSMQ installed on your computer in Workgroup mode.

For information about using the samples, see the following topics:

To build the sample using the command prompt

  1. Open a Command Prompt window and navigate to one of the language-specific subdirectories under the Technologies\ComponentServices\QueuedComponents directory.

  2. Type msbuild QueuedComponentsCS.sln or msbuild QueuedComponentsVB.sln, depending on your choice of programming language, at the command line.

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to one of the language-specific subdirectories under the Technologies\ComponentServices\QueuedComponents directory.

  2. Double-click the icon for QueuedComponentsCS.sln or QueuedComponentsVB.sln, depending on your choice of programming language, to open the file in Visual Studio.

  3. On the Build menu, click Build Solution.

To register and install the assembly in the GAC

  1. Navigate to the directory that contains the built assembly.

  2. Type regsvcs QCDemoSvr.dll at the command line to register the assembly.

  3. Type gacutil –i QCDemoSvr.dll at the command line to install the assembly in the GAC.

To run the sample

  1. Open the Command Prompt window or Windows Explorer and navigate to the directory that contains the new executable.

  2. Type QCDemo.exe at the command line, or start QCDemo.exe by double-clicking it in Windows Explorer.

  3. Click the button labeled Send Queued Msg. Change the string value in the text edit field, and click Send Queued Msg a second time. This should place two packaged method calls in the queue.

  4. Examine the messages in the QCDemoSvr queue. Right-click My Computer and select Manage from the pop-up menu. Expand Services and Applications\Message Queueing\Public Queues in the Computer Management console. You should see a queue named qcdemosvr in this node. The queue name corresponds to the name of the COM+ application that holds the queued component. This application is examined in a later step.

  5. Expand qcdemosvr and select Queue messages. You should see two messages in the right-hand pane, corresponding to the two queued component method calls that were made in the client application.

  6. Launch the Component Services administrative tool.

  7. Locate the QCDemoSvr COM+ application by expanding Component Services\Computers\My Computer\COM+ Applications in the left-hand COM+ explorer pane.

  8. Right-click the QCDemoSvr application and select Start from the popup menu. This activates the server component. The listener/player pulls messages from the qcdemosvr queue and calls into the server. As a result, you should see two message boxes that contain the text strings from the original calls from the sample client application.

  9. You can return to the Computer Management console to observe that the qcdemosvr no longer contains queued messages. Subsequent calls from the client application are passed directly to the server and message boxes will appear immediately for each button click.

    NoteNote

    In Windows 2000, you must shut down the QCDemoSvr COM+ application (by right-clicking the application in the COM+ explorer and selecting Shut Down) to return to queuing messages. The QCDemo client executable must be closed before the QCDemoSvr COM+ application will shut down.

To uninstall the sample

  1. Navigate to the directory where you ran the msbuild.exe or launched the .sln file.

  2. At the command prompt, type msbuild.exe QueuedComponentsCS.sln /t:Clean or msbuild.exe QueuedComponentsVB.sln /t:Clean, depending on your choice of programming language. This action calls the .NET Services Installation Tool (Regsvcs.exe) and the Global Assembly Cache Tool (Gacutil.exe) with the /u switch to remove the sample files from the COM+ catalog and the Global Assembly Cache.

Requirements

Platform: Windows 2000, Windows XP, Windows Server 2003

.NET Framework Version: 2.0, 1.1, 1.0

Remarks

For more information about sample binary creation and registration steps, review the comments in the source code files.

Queued Components is a COM+ feature built on top of Message Queuing Services (MSMQ) that provides a mechanism for invoking and executing components asynchronously. When a client makes a call to a queued object, the call is actually made to a recorder, which packages it as a message and places that message in a queue. A listener reads the message from the queue and passes it to the player. The player makes the actual method calls on the server object. The C# version of the component name as viewed in the Component Services administrative tool is QCDemoServerCS.QComponent. The Visual Basic version is QCDemoServerVB.QComponent.

NoteNote

 You must register the QCDemoSvr.dll assembly to set up the Message Queue, and install the assembly to the global assembly cache (GAC). The .NET Services Installation tool (regsvcs.exe) is located in the %system root%\Microsoft.Net\Framework\<runtime version> directory and the Global Assembly Cache tool (gacutil.exe) is located in the \SDK\<version>\Bin directory.

The server must be activated to receive queued messages. Server components can be activated manually, using scripting in combination with the task scheduler, or programmatically. This sample activates the server component manually.

The sample consists of a client application and a managed object marked for InterfaceQueuing. The listener is enabled by means of a class attribute. On building the application, COM+ creates a queue whose name is the same as the specified COM+ application.

The client application contains a single button. Clicking the button invokes the queued component recorder by means of a queue moniker. All calls through the returned reference are packaged and placed in the appropriate message queue.

Queued method calls are unpackaged and delivered to the actual server component when it is activated in the Component Services administrative tool. The sample server displays a simple message box to show that the call has reached the server.

See Also

Reference

ApplicationQueuingAttribute
Component
InterfaceQueuingAttribute
Queue
System.ComponentModel
System.EnterpriseServices
System.Reflection
System.Runtime.InteropServices
System.Windows.Forms

Concepts

Queued Components

Other Resources

Using Messaging Components
Writing Serviced Components
Creating Component Queues