Author |
Message
|
msimoneau |
Posted: Tue Sep 23, 2003 12:25 pm Post subject: MQ Series with C# |
|
|
Newbie
Joined: 23 Sep 2003 Posts: 2
|
I have an application written in VB6 where I get a list of queues defined to the queue manager. I need to rewrite this application in C#, but have been having problems writing the code. I have downloaded and installed service pack MQ7P, and have C# getting and putting messages onto a queue. Does anyone have experience in C# using the PCF classes? |
|
Back to top |
|
 |
bduncan |
Posted: Thu Sep 25, 2003 4:43 pm Post subject: |
|
|
Padawan
Joined: 11 Apr 2001 Posts: 1554 Location: Silicon Valley
|
I don't believe PCF is available in C# API... _________________ Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator |
|
Back to top |
|
 |
msimoneau |
Posted: Mon Oct 13, 2003 7:34 pm Post subject: Code Sample |
|
|
Newbie
Joined: 23 Sep 2003 Posts: 2
|
Below is a code sample that I finally got working to list queue names. I would like to note that sample code written by Dino Chiesa was the final key for me to get my code working. My problem was around writting and reading strings.
Below is code from my applicaiton
MQQueue mqQueue;
mqQueue = QueueMgr.AccessQueue(QueueMgr.CommandInputQueueName,MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
MQMessage qMsg = new MQMessage();
qMsg.Format = MQC.MQFMT_ADMIN;
qMsg.MessageType = MQC.MQMT_REQUEST;
qMsg.Feedback = MQC.MQFB_NONE;
//Define MQCFH Stuff
int MQCFH_Type = CMQCFC.MQCFT_COMMAND;
int MQCFH_StrucLength = CMQCFC.MQCFH_STRUC_LENGTH;
int MQCFH_Version = CMQCFC.MQCFH_VERSION_1;
int MQCFH_Command = CMQCFC.MQCMD_INQUIRE_Q_NAMES;
int MQCFH_MsgSeqNumber = CMQCFC.MQCFC_LAST;
int MQCFH_Control = CMQCFC.MQCFC_LAST;
int MQCFH_CompCode = MQC.MQCC_OK;
int MQCFH_Reason = MQC.MQRC_NONE;
int MQCFH_ParameterCount = 2;
//Define String
string QName_string = "*" + new String(' ',MQC.MQ_Q_NAME_LENGTH - 1);
//Define MQCFST
int MQCFST_Type = CMQCFC.MQCFT_STRING;
int MQCFST_StrucLength = CMQCFC.MQCFST_STRUC_LENGTH_FIXED + MQC.MQ_Q_NAME_LENGTH;
int MQCFST_Parameter = MQC.MQCA_Q_NAME;
int MQCFST_CodedCharSetId= MQC.MQCCSI_DEFAULT;
int MQCFST_StringLength = QName_string.Length;
//Define MQCFIN
int MQCFIN_Type = CMQCFC.MQCFT_INTEGER;
int MQCFIN_StrucLength = CMQCFC.MQCFIN_STRUC_LENGTH;
int MQCFIN_Parameter = MQC.MQIA_Q_TYPE;
int MQCFIN_Value = MQC.MQQT_LOCAL;
//Put the values onto the queue
qMsg.WriteInt32(MQCFH_Type);
qMsg.WriteInt32(MQCFH_StrucLength);
qMsg.WriteInt32(MQCFH_Version);
qMsg.WriteInt32(MQCFH_Command);
qMsg.WriteInt32(MQCFH_MsgSeqNumber);
qMsg.WriteInt32(MQCFH_Control);
qMsg.WriteInt32(MQCFH_CompCode);
qMsg.WriteInt32(MQCFH_Reason);
qMsg.WriteInt32(MQCFH_ParameterCount);
qMsg.WriteInt32(MQCFST_Type);
qMsg.WriteInt32(MQCFST_StrucLength);
qMsg.WriteInt32(MQCFST_Parameter);
qMsg.WriteInt32(MQCFST_CodedCharSetId);
qMsg.WriteInt32(MQCFST_StringLength);
byte[] b = new byte[System.Text.Encoding.ASCII.GetByteCount(QName_string)];
System.Text.Encoding.ASCII.GetBytes(QName_string,0,b.Length,b,0);
qMsg.Write(b,b.Length);
qMsg.WriteInt32(MQCFIN_Type);
qMsg.WriteInt32(MQCFIN_StrucLength);
qMsg.WriteInt32(MQCFIN_Parameter);
qMsg.WriteInt32(MQCFIN_Value);
qMsg.ReplyToQueueName = "SYSTEM.DEFAULT.LOCAL.QUEUE";
try
{
mqQueue.Put(qMsg, new MQPutMessageOptions());
}
catch (Exception exp)
{
int xx = qMsg.CompletionCode;
int yy = qMsg.ReasonCode;
}
//define an array list to hold any messages to be sent back
ArrayList QueueNames = new ArrayList();
MQMessage rMsg = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
rMsg.CorrelationId = qMsg.MessageId;
gmo.Options = MQC.MQGMO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT;
gmo.WaitInterval = 5000;
gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID;
MQQueue rQueue;
rQueue = QueueMgr.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
try
{
rQueue.Get(rMsg, gmo);
}
catch (Exception exp)
{
int xx = rMsg.CompletionCode;
int yy = rMsg.ReasonCode;
}
if (rMsg.CompletionCode == MQC.MQCC_OK)
{
int MQCFH_type = rMsg.ReadInt32(); //Get the MQCFT_Command
int MQCFH_StrucLength = rMsg.ReadInt32();
int MQCFH_version = rMsg.ReadInt32();
int MQCFH_command = rMsg.ReadInt32();
int MQCFH_msgSeqNum = rMsg.ReadInt32();
int MQCFH_control = rMsg.ReadInt32();
int MQCFH_compcode = rMsg.ReadInt32();
int MQCFH_reasoncode = rMsg.ReadInt32();
int MQCFH_parmCount = rMsg.ReadInt32();
int MQCFSL_Type = rMsg.ReadInt32(); //Get the MQCFT_
int MQCFSL_StrucLength = rMsg.ReadInt32();
int MQCFSL_Parameter = rMsg.ReadInt32();
int MQCFSL_CodedCharSetId = rMsg.ReadInt32();
int MQCFSL_Count = rMsg.ReadInt32();
int MQCFSL_StringLength = rMsg.ReadInt32();
byte[] b;
for (int i=0; i<MQCFSL_Count; i++)
{
b=rMsg.ReadBytes(MQCFSL_StringLength);
QueueNames.Add(System.Text.Encoding.ASCII.GetString(b));
}
}
return QueueNames; |
|
Back to top |
|
 |
ddm |
Posted: Mon Nov 17, 2003 3:12 pm Post subject: Re: Sample Code |
|
|
Apprentice
Joined: 17 Nov 2003 Posts: 40
|
I am pretty new with MQ API. Do you have to manually define all the MQ Constants? |
|
Back to top |
|
 |
kman |
Posted: Mon Nov 17, 2003 10:58 pm Post subject: |
|
|
Partisan
Joined: 21 Jan 2003 Posts: 309 Location: Kuala Lumpur, Malaysia
|
No. You don't need to manually define all the constant. What you see posted here is a PCF programming written using C. PCF si used for mq administration programming. PCF = Programmable Command Format. Don't be turned off by that sample.
What you normally do with MQ API is to write programs for business processing. And that one is the same as your other programs. You just define the variables and constants you want to use. No need to define MQ constants.
Take a look at the Programming Guide, or the Programming Reference Manual. Follow the Docuemntation link found at the top of the page. |
|
Back to top |
|
 |
JasonE |
Posted: Tue Nov 18, 2003 2:24 am Post subject: |
|
|
Grand Master
Joined: 03 Nov 2003 Posts: 1220 Location: Hursley
|
The .net classes do ship with an undocumented pcf support. Its broken in some cases in csd05, but there is a fix available which should go in csd06. In this specific case it appears to work:
using System;
using IBM.WMQ;
using IBM.WMQ.PCF;
namespace pcfquery
{
class pcfquery
{
[STAThread]
static int Main(String[] args)
{
PCFMessageAgent agent = new
PCFMessageAgent("QM");
PCFMessage reqeuestMessage = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q_NAMES);
reqeuestMessage.AddParameter(MQC.MQCA_Q_NAME, "SYSTEM*");
PCFMessage[] response = agent.Send(reqeuestMessage);
string[] queueNames =
response[0].GetStringListParameterValue(CMQCFC.MQCACF_Q_NAMES);
for (int i = 0; i < queueNames.Length; i++)
{
System.Console.WriteLine("Queue "+i+" : "+queueNames[i]);
}
return queueNames.Length;
}
}
} |
|
Back to top |
|
 |
|