[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 898
  • Last Modified:

C# console application

hai,
i wnat write program for  MQ Series(Series).for that what i must do.means which name space i must import,etc.give me one code.i;ve got one program here.in that program thay are using MQ name space.i am giving the code below.pls find the error.




using System;

namespace dinoch.demo
{

      public class DotNetMqHello
      {
      
      
            private MQAX200.IMQQueueManager200  MyMqManager;
            private MQAX200.IMQSession200       MyMqSession;
            private MQAX200.IMQQueue200         MyMqQueue;
            public DotNetMqHello()
            {
                  MyMqSession = new MQAX200.MQSessionClass();
                  MyMqSession.ExceptionThreshold = 3;
            }

            public static void Main()
            {
                  DotNetMqHello Hello= new DotNetMqHello();
                  Hello.DoIt();
            }

            private void DoIt()
            {
                  DoConnect();
                  DoPut();
                  DoGet();
            }

            private void DoConnect()
            {
                  int OpenOptions;
                  String qmName= ""; // use the default local Queue Mgr
                  Object obj = MyMqSession.AccessQueueManager(qmName);

                  if (!(obj is MQAX200.IMQQueueManager200) )
                        Console.WriteLine("Sorry! Could Not get a Queue Manager.");

                  else
                  {
                        Console.WriteLine("Yes! Got a Queue Manager.");
                        MyMqManager = (MQAX200.IMQQueueManager200) obj;
                        if (MyMqManager != null)
                        {
                              if(MyMqManager.IsConnected)
                              {
                                    OpenOptions = (int) MQAX200.MQ.MQOO_INPUT_AS_Q_DEF + (int) MQAX200.MQ.MQOO_OUTPUT;
                                    MyMqQueue = (MQAX200.IMQQueue200) MyMqManager.AccessQueue("postcard", OpenOptions,"","","");
                                    if(MyMqQueue.IsOpen)
                                          Console.WriteLine("Connected to " + MyMqManager.name + "." + MyMqQueue.name ) ;
                              }
                        }
                  }
            }

            private void DoPut()
            {
                  MQAX200.IMQMessage200 Message;
                  MQAX200.IMQPutMessageOptions200 MessageOptions;

                  Message = (MQAX200.IMQMessage200) MyMqSession.AccessMessage();
                  Message.WriteString(System.DateTime.Now.ToString() + ": This is the test message" );

                  MessageOptions = (MQAX200.IMQPutMessageOptions200) MyMqSession.AccessPutMessageOptions();

                  MyMqQueue.ClearErrorCodes();
                  MyMqQueue.Put(Message, MessageOptions);

                  if(MyMqQueue.CompletionCode == 0)
                        Console.WriteLine("Put Succeeded.");

                  else if(MyMqQueue.CompletionCode == 2)
                        Console.WriteLine("Put Failed (" + MyMqQueue.ReasonName + ")");
            }

            private void DoGet()
            {
                  MQAX200.IMQMessage200 Message;
                  MQAX200.IMQGetMessageOptions200 MessageOptions;

                  Message = (MQAX200.IMQMessage200) MyMqSession.AccessMessage();
                  MessageOptions = (MQAX200.IMQGetMessageOptions200) MyMqSession.AccessGetMessageOptions();

                  if(MyMqQueue.IsOpen)
                  {
                        MyMqQueue.ClearErrorCodes();
                        // need to specify Missing.Value here because of an issue with the optional 3rd param (length)
                        MyMqQueue.Get(Message,MessageOptions, System.Reflection.Missing.Value);

                        if(MyMqQueue.CompletionCode == 0)
                        {
                              Console.WriteLine("Get Succeeded.");
                              Console.WriteLine(Message.ReadString(Message.MessageLength));
                        }

                        else if(MyMqQueue.CompletionCode == 2)
                              Console.WriteLine("Get Failed (" + MyMqQueue.ReasonName + ")");
                  }
            }

      } // end class

} // end namespace
0
beeravally
Asked:
beeravally
1 Solution
 
TheC2Commented:
I haven't worked with MQSeries, but in most cases you should receive a few DLLs from along with the software that are .NET assemblies, and you need to add them to your project, only then you will have access to their namespaces.
What error do you get?
0
 
heintalusCommented:
You need to add a reference to amqmdnet.dll which you should find in
C:\Program Files\ibm\WebSphere MQ\bin

then add the follwoing using statement

using IBM.WMQAX;

HTH
Andy
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now