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:
- 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.
- Change the name to MQServicedCom and the desired location. Click OK.
- 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.
- Add the following to the
using
block: using System.EnterpriseServices;
using System.Runtime.InteropServices;
using System.Diagnostics;
using IBM.WMQAX;
- Select the class view by clicking the View menu and change the class name from
Class1
to MQServices
.
- 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.
- Make sure the
MQServices
class implements both the ServicedComponent
and IMQServices
interface in the following way: public class MQServices : ServicedComponent, IMQServices
- Open the Visual Studio .NET 2003 command prompt by clicking Start, Programs, Microsoft Visual Studio .NET 2003, and Visual Studio .NET Tools.
- 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.
- 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.
- It's ready to be built. Select Build Solution from the Build menu to build the
MQServicedCom
assembly.
- From the command prompt, navigate to the bin folder where the built assembly resides. Register the assembly by typing: RegSvcs MQServicedCom.dll.
- 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.