Click here to Skip to main content
Click here to Skip to main content

A C# Serviced Component for Websphere MQ 5.3

, 29 Oct 2004
Rate this:
Please Sign up or sign in to vote.
A C# .NET serviced component that encapsulates MQ PUT and MQ GET.

Introduction

This is an article on what you need and how to write a serviced component in C# that encapsulates all the intricacies of communicating with the IBM Mainframe.

Background

I was assigned a new project that required to write a COM+ program to enable the clients (mainly Classic ASP and ASP.NET) to synchronize our online user profile with the user store on the IBM Mainframe. Before I started the project, I was surprised to find only a few articles on programming WebSphere MQ in the .NET environment. Therefore, I thought of sharing my work here to help fellow programmers who need to work with IBM Websphere MQ, to save time and headaches.

Using the code

In order to use and test the code, you need to have IBM WebSphere MQ 5.3 with CSD05 or higher installed. Also install the AMQMDNET.DLL onto the GAC if not already done, by the WebSphere MQ 5.3 installation. Create the Queue Manager, Queue and Channel. You can follow the article Message Queuing by MQSeries with C# by Rosi Reddy to create the necessary WebSphere MQ configuration.

Here are the steps to create the project solution:

  1. Open a new project by clicking New on the File menu. The New Project dialog box comes up, and then select New C# projects on the Project type box. Select Class Library for the templates on the right.
  2. Change the name to MQServicedCom and the desired location. Click OK.
  3. Right click on Reference and select both the WebSphere MQ classes for .NET and System.EnterpriseServices from the Add Reference dialog box and click OK.
  4. Add the following to the using block:
    using System.EnterpriseServices; // for ServicedComponent 
    using System.Runtime.InteropServices; //for Class Interface 
    using System.Diagnostics; //for Windows Event Logging 
    using IBM.WMQAX; //for IBM Websphere MQ in .NET
  5. Select the class view by clicking the View menu and change the class name from Class1 to MQServices.
  6. Add all the code for the interface, class, and methods to the MQServices class. In our case, copy and paste the MQPutMessage and MQGetMessage methods, and the IMQServices interface. Make sure all the attributes i.e. [JustInTimeActivation()] are also copied.
  7. Make sure the MQServices class implements both the ServicedComponent and IMQServices interface in the following way:
    public class MQServices : ServicedComponent, IMQServices
  8. Open the Visual Studio .NET 2003 command prompt by clicking Start, Programs, Microsoft Visual Studio .NET 2003, and Visual Studio .NET Tools.
  9. The serviced component needs to have strong name. After the command prompt is opened, navigate to the MQServicedCom project folder, type: sn -k MQServicedComKey.snk.
  10. Copy and paste the source file's AssemblyInfo.cs onto your project's AssemblyInfo.cs file.

    Please note that you should replace all the GUIDs both from the MQServices.cs and the AssemblyInfo.cs files to ensure uniqueness. You can generate a new GUID by clicking the Tools menu and selecting Create GUID. Then copy and paste the newly generated GUID for the replacement.

  11. It's ready to be built. Select Build Solution from the Build menu to build the MQServicedCom assembly.
  12. From the command prompt, navigate to the bin folder where the built assembly resides. Register the assembly by typing: RegSvcs MQServicedCom.dll.
  13. Install it to the GAC by typing: gacutil /i MQServicedCom.dll.

    That's all. Now you have a serviceable serviced component. To verify it, open up the Component Services Manager. You can find the COM+ application MQ service component library where this title was taken from the AssemblyInfo.cs file's ApplicationName attribute. You can use the TestCom.vbs file to test this newly created and registered serviced component. Good luck and have fun.

Points of interest

Two books that helped me greatly on writing this Enterprise Serviced components are:

History

  • Created version 1.0.0.0 on October 29th, 2004.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

eleung
Web Developer
United States United States
Fascinated with .Net.

Comments and Discussions

 
GeneralRemote Queue PinmemberDigitalBay25-Feb-05 6:01 
GeneralRe: Remote Queue Pinmembereleung28-Feb-05 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 29 Oct 2004
Article Copyright 2004 by eleung
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid