|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
C# with MQSeries 5.3 sends a message with an invalid format |
« View previous topic :: View next topic » |
Author |
Message
|
portnovj007 |
Posted: Thu May 05, 2005 1:01 pm Post subject: C# with MQSeries 5.3 sends a message with an invalid format |
|
|
Newbie
Joined: 05 May 2005 Posts: 2
|
I am using C# to send a message to MQSeries 5.3 server with the standard characterset. When viewing the data in MQSeries test utility, the message contents seem to have a different format.
I know that WriteString function needs to be replaced with WriteUTF to avoid extra period characters between valid characters displayed in the message. However, WriteUTF function add 2 bytes to the beginning of the
contents when it writes data to the MQSeries 5.3 queue.
I undertand that characterset affects the way, WriteString writes data to
the queue. I have tried using characterset of 437, 1208. It does not seem to make a difference.
Below are the options my code uses:
const string RFH2_STRUCID_DEFAULT = "RFH ";
const int RFH2_VERSION_DEFAULT = 2;
const int RFH2_STRUCLENGTH_DEFAULT = 36;
const int RFH2_ENCODING_DEFAULT = x00000222;
const int RFH2_CODEDCHARSETID_DEFAULT = 1208;
const string RFH2_FORMAT_DEFAULT = "MQSTR ";
const int RFH2_FLAGS_DEFAULT = 0;
const int RFH2_NAMEVALUECCSID_DEFAULT = 1208;
const string MCD_DATA_DEFAULT = "<mcd><Msd>jms_text</Msd></mcd>";
const string FORMAT_MESSAGE_HRF2 = "MQHRF2 ";
Any help would be appreciated.
Sincerely,
JP |
|
Back to top |
|
 |
malammik |
Posted: Thu May 05, 2005 1:07 pm Post subject: |
|
|
 Partisan
Joined: 27 Jan 2005 Posts: 397 Location: Philadelphia, PA
|
I dont have a solution for you but I wanted to confirm that I ran into the same problem. We did a LOT of testing back then and we narrowed it down to either a bug in Windows or MQ. I suggest that you open up a PMR with IBM. _________________ Mikhail Malamud
http://www.netflexity.com
http://groups.google.com/group/qflex |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri May 06, 2005 3:15 am Post subject: Re: C# with MQSeries 5.3 sends a message with an invalid for |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
portnovj007 wrote: |
However, WriteUTF function add 2 bytes to the beginning of the contents when it writes data to the MQSeries 5.3 queue. |
That's the byte order mark. I think you need that to be proper UTF. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
JasonE |
Posted: Fri May 06, 2005 3:39 am Post subject: |
|
|
Grand Master
Joined: 03 Nov 2003 Posts: 1220 Location: Hursley
|
WriteString honours the codepage the message is configured to be in, so changing it to eg. 437 or 850 before you write the rfh header portion might help.
UTF8 is, as described, a length followed by the UTF encoded chars (and if you use a character over 0x7f, it takes 2 bytes). |
|
Back to top |
|
 |
portnovj007 |
Posted: Fri May 06, 2005 5:05 am Post subject: Some progress made |
|
|
Newbie
Joined: 05 May 2005 Posts: 2
|
I have changed the CharSet to 437. Now the WriteString function does not output invalid characters.
I also am writing the RHF header with WriteBytes (instead of WriteString or WriteUTF). This gives me a valid "RHF" without leading bytes or invalid characters between the "RHF" text. The reason is that RHF header is bytes, not string.
I am still getting some strange invalid characters ("h" and "\"). Not sure why this is happening. Any ideas?
Below is a section of a sample of my testing code:
---------------------------------------------------------
const string RFH2_STRUCID_DEFAULT = "RFH ";
const int RFH2_VERSION_DEFAULT = 2;
const int RFH2_STRUCLENGTH_DEFAULT = 36;
const int RFH2_ENCODING_DEFAULT = 0x00000222;
const int RFH2_CODEDCHARSETID_DEFAULT = 437;
const string RFH2_FORMAT_DEFAULT = "MQSTR ";
const int RFH2_FLAGS_DEFAULT = 0;
const int RFH2_NAMEVALUECCSID_DEFAULT = 437;
const string MCD_DATA_DEFAULT = "<mcd><Msd>jms_text</Msd></mcd>";
const string FORMAT_MESSAGE_HRF2 = "MQHRF2 ";
private MQQueueManager m_qMgr;
private MQQueue m_SystemDefaultLocalQueue;
private MQMessage m_Msg;
private MQPutMessageOptions m_mqpo;
//Structure definition
public struct MQRFH2
{
public string StrucId;
public int Version;
public int StrucLength;
public int Encoding;
public int CodedCharSetId;
public string Format;
public int Flags;
public int NameValueCCSID;
public MQRFH2(string sStrucId, int iVersion, int iStrucLength, int iEncoding, int iCodedCharSetId, string sFormat, int iFlags, int iNameValueCCSID)
{
StrucId = sStrucId;
Version = iVersion;
StrucLength = iStrucLength;
Encoding = iEncoding;
CodedCharSetId = iCodedCharSetId;
Format = sFormat;
Flags = iFlags;
NameValueCCSID = iNameValueCCSID;
}
}
/// <summary>
/// usr folder elements and their defaults values
/// </summary>
private string _usrRoot = "ADP";
private string _usrDataClass = "PAYROLL";
private string _usrDataSubClass = "";
private string _usrVerb = "GET";
private string _usrNoun = "JURISDICTION";
private string _usrDataVer = "001:000";
private string _usrMktSgmnt = "MAJ";
private string _usrSrcAppID = "ESTART";
private string _usrServReg = "";
private string _usrCustID = "";
private string _usrCompID = "";
private string _usrSrcSysID = "";
private string _usrSrcAppVer = "001:000";
private string _usrAPIName = "";
private string _usrAPIVer = "";
private string _usrAPIHdrVer = "002:000";
private string _usrPldEffTime = "20050419T105300000Z";
private string _usrPldFmt = "XML";
private string _usrAppSpecificID = "";
private string _usrMsgCorrelationID = "";
private string _usrADPSegCont = "";
private string _usrADPSegNo = "";
private string _usrDiagValidate = "";
private string _usrDiagPing = "";
///
/// public interface for usr folder elements
///
public string usrRoot { get { return this._usrRoot; } set { this._usrRoot = value; }}
public string usrDataClass { get { return this._usrDataClass; } set { this._usrDataClass = value; }}
public string usrDataSubClass { get { return this._usrDataSubClass; } set { this._usrDataSubClass = value; }}
public string usrVerb { get { return this._usrVerb; } set { this._usrVerb = value; }}
public string usrNoun { get { return this._usrNoun; } set { this._usrNoun = value; }}
public string usrDataVer { get { return this._usrDataVer; } set { this._usrDataVer = value; }}
public string usrMktSgmnt { get { return this._usrMktSgmnt; } set { this._usrMktSgmnt = value; }}
public string usrSrcAppID { get { return this._usrSrcAppID; } set { this._usrSrcAppID = value; }}
public string usrServReg { get { return this._usrServReg; } set { this._usrServReg = value; }}
public string usrCustID { get { return this._usrCustID; } set { this._usrCustID = value; }}
public string usrCompID { get { return this._usrCompID; } set { this._usrCompID = value; }}
public string usrSrcSysID { get { return this._usrSrcSysID; } set { this._usrSrcSysID = value; }}
public string usrSrcAppVer { get { return this._usrSrcAppVer; } set { this._usrSrcAppVer = value; }}
public string usrAPIName { get { return this._usrAPIName; } set { this._usrAPIName = value; }}
public string usrAPIVer { get { return this._usrAPIVer; } set { this._usrAPIVer = value; }}
public string usrADPHdrVer { get { return this._usrAPIHdrVer; } set { this._usrAPIHdrVer = value; }}
public string usrPldEffTime { get { return this._usrPldEffTime; } set { this._usrPldEffTime = value; }}
public string usrPldFmt { get { return this._usrPldFmt; } set { this._usrPldFmt = value; }}
public string usrAppSpecificID { get { return this._usrAppSpecificID; } set { this._usrAppSpecificID = value; }}
public string usrMsgCorrelationID { get { return this._usrMsgCorrelationID; } set { this._usrMsgCorrelationID = value; }}
public string usrADPSegCont { get { return this._usrADPSegCont; } set { this._usrADPSegCont = value; }}
public string usrADPSegNo { get { return this._usrADPSegNo; } set { this._usrADPSegNo = value; }}
public string usrDiagValidate { get { return this._usrDiagValidate; } set { this._usrDiagValidate = value; }}
public string usrDiagPing { get { return this._usrDiagPing; } set { this._usrDiagPing = value; }}
private string _pscCommand = "Publish";
private string _pscTopic = "";
public string pscCommand { get { return this._pscCommand; } set { this._pscCommand = value; }}
public string pscTopic { get { return this._pscTopic; } set { this._pscTopic = value; }}
public void rfh2message()
{
//
// initialize the MQEnvironment
//
}
public string SendMessage(string pQueueManager, string pQueueName, string pData)
{
//Message generation
// MQRFH2 rfh2 = new MQRFH2(RFH2_STRUCID_DEFAULT, RFH2_VERSION_DEFAULT,
// RFH2_STRUCLENGTH_DEFAULT, RFH2_ENCODING_DEFAULT, RFH2_CODEDCHARSETID_DEFAULT,
// RFH2_FORMAT_DEFAULT, RFH2_FLAGS_DEFAULT, RFH2_NAMEVALUECCSID_DEFAULT);
MQRFH2 rfh2 = new MQRFH2(RFH2_STRUCID_DEFAULT, RFH2_VERSION_DEFAULT,
RFH2_STRUCLENGTH_DEFAULT, RFH2_ENCODING_DEFAULT, RFH2_CODEDCHARSETID_DEFAULT,
RFH2_FORMAT_DEFAULT, RFH2_FLAGS_DEFAULT, RFH2_NAMEVALUECCSID_DEFAULT);
string Data = pData;
string Results = "";
string mcd_data = MCD_DATA_DEFAULT;
#region user folder
///
/// opening tag
/// ///
string usr_data = "<usr>";
///
/// Topic
///
usr_data += ("<Root>" + this._usrRoot + "</Root>");
usr_data += ("<DataClass>" + this._usrDataClass + "</DataClass>");
usr_data += ("<DataSubClass>" + this._usrDataSubClass + "</DataSubClass>");
usr_data += ("<Verb>" + this._usrVerb + "</Verb>");
usr_data += ("<Noun>" + this._usrNoun + "</Noun>");
usr_data += ("<DataVer>" + this._usrDataVer + "</DataVer>");
usr_data += ("<MktSgmnt>" + this._usrMktSgmnt + "</MktSgmnt>");
usr_data += ("<SrcAppID>" + this._usrSrcAppID + "</SrcAppID>");
usr_data += ("<ServReg>" + this._usrServReg + "</ServReg>");
usr_data += ("<CustID>" + this._usrCustID + "</CustID>");
usr_data += ("<CompID>" + this._usrCompID + "</CompID>");
///
/// SourceApp
///
usr_data += ("<SrcSysID>" + this._usrSrcSysID + "</SrcSysID>");
usr_data += ("<SrcAppVer>" + this._usrSrcAppVer + "</SrcAppVer>");
///
/// API
///
usr_data += ("<APIName>" + this._usrAPIName + "</APIName>");
usr_data += ("<APIVer>" + this._usrAPIVer + "</APIVer>");
///
/// Header Information
///
usr_data += ("<ADPHdrVer>" + this._usrAPIHdrVer + "</ADPHdrVer>");
///
/// Payload
///
usr_data += ("<PldEffTime>" + this._usrPldEffTime + "</PldEffTime>");
usr_data += ("<PldFmt>" + this._usrPldFmt + "</PldFmt>");
///
/// Content Identification
///
usr_data += ("<AppSpecificID>" + this._usrAppSpecificID + "</AppSpecificID>");
usr_data += ("<MsgCorrelationID>" + this._usrMsgCorrelationID + "</MsgCorrelationID>");
///
/// ADP Segmentation
///
usr_data += ("<ADPSegCont>" + this._usrADPSegCont + "</ADPSegCont>");
usr_data += ("<ADPSegNo>" + this._usrADPSegNo + "</ADPSegNo>");
///
/// Diagnostics
///
usr_data += ("<DiagValidate>" + this._usrDiagValidate + "</DiagValidate>");
usr_data += ("<DiagPing>" + this._usrDiagPing + "</DiagPing>");
///
/// closing tag
///
usr_data += "</usr>";
#endregion
#region psc folder
///
/// opening tag
///
string psc_data = "<psc>";
psc_data += "<Command>" + this._pscCommand + "</Command>";
psc_data += "<Topic>" + this._pscTopic + "</Topic>";
///
/// closing tag
///
psc_data += "</psc>";
#endregion
#region jms folder
///
/// opening tag
///
string jms_data = "<jms>";
jms_data += "<Dst>queue:///" + pQueueName + "</Dst>";
jms_data += "<Tms>" + (((long)System.DateTime.Now.Ticks) - 621355968000000000)/10000 + "</Tms>";
jms_data += "<Dlv>2</Dlv>";
///
/// closing tag
///
jms_data += "</jms>";
#endregion
Data = "<Data>" + Data + "</Data>";
int mcd_len = ((mcd_data.Length - 1) / 4) * 4 + 4;
int jms_len = ((jms_data.Length - 1) / 4) * 4 + 4;
int usr_len = ((usr_data.Length - 1) / 4) * 4 + 4;
int psc_len = ((psc_data.Length - 1) / 4) * 4 + 4;
int msg_len = ((Data.Length - 1) / 4) * 4 + 4;
/// int msg_len = Data.Length;
//Padding of sections (again attention to the spaces)
mcd_data += " ";
mcd_data = mcd_data.Substring(0, mcd_len);
jms_data += " ";
jms_data = jms_data.Substring(0, jms_len);
usr_data += " ";
usr_data = usr_data.Substring(0, usr_len);
psc_data += " ";
psc_data = psc_data.Substring(0, psc_len);
Data += " ";
Data = Data.Substring(0, msg_len);
try
{
this.m_qMgr = new MQQueueManager(pQueueManager);
this.m_SystemDefaultLocalQueue = this.m_qMgr.AccessQueue(pQueueName, MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_OUTPUT);
///
/// create the message
///
this.m_Msg = new MQMessage();
//jp
this.m_Msg.Format = MQC.MQFMT_RF_HEADER_2; //FORMAT_MESSAGE_HRF2;
//this.m_Msg.Format = MQC.MQFMT_STRING;
this.m_Msg.Persistence = MQC.MQPER_PERSISTENT;
this.m_Msg.WriteBytes ("RFH ");
// this.m_Msg.WriteUTF (rfh2.StrucId);
// this.m_Msg.WriteInt4 (rfh2.Version);
this.m_Msg.Version = MQC.MQPMO_VERSION_2;
//this.m_Msg.WriteInt4 (36 + mcd_len + usr_len + msg_len + 12);
this.m_Msg.Encoding = 0x00000222;// MQC.MQENC_INTEGER_NORMAL;
// this.m_Msg.WriteInt4 (rfh2.Encoding);
// this.m_Msg.WriteInt4 (rfh2.CodedCharSetId);
this.m_Msg.CharacterSet = 437;// MQC.MQCCSI_Q_MGR;
this.m_Msg.Format = MQC.MQFMT_STRING; //FORMAT_MESSAGE_HRF2;
// this.m_Msg.WriteString (rfh2.Format);
// this.m_Msg.WriteUTF (rfh2.Format);
// this.m_Msg.WriteInt4 (rfh2.Flags); //NOT SURE WHY WE NEED THIS HERE?
// this.m_Msg.WriteInt4 (rfh2.NameValueCCSID); //NOT SURE WHY WE NEED THIS HERE?
this.m_Msg.WriteInt4 (psc_len);
this.m_Msg.WriteString (psc_data);
// this.m_Msg.WriteUTF (psc_data);
this.m_Msg.WriteInt4 (mcd_len);
this.m_Msg.WriteString (mcd_data);
// this.m_Msg.WriteUTF (mcd_data);
// this.m_Msg.WriteInt4 (jms_len);
// this.m_Msg.WriteUTF (jms_data);
this.m_Msg.WriteInt4 (usr_len);
this.m_Msg.WriteString (usr_data);
// this.m_Msg.WriteUTF (usr_data);
this.m_Msg.WriteInt4 (msg_len);
this.m_Msg.WriteString (Data);
// this.m_Msg.WriteUTF(Data);
//JP
// this.m_Msg.PutApplicationType = MQC.MQAT_WINDOWS;
///
/// put the message on the queue
///
this.m_mqpo = new MQPutMessageOptions();
//jp
// this.m_mqpo.Version = IBM.WMQ.MQC.MQPMO_VERSION_2;
this.m_SystemDefaultLocalQueue.Put(this.m_Msg, this.m_mqpo);
Results = "Message sent<br>"; |
|
Back to top |
|
 |
EddieA |
Posted: Fri May 06, 2005 10:40 am Post subject: Re: C# with MQSeries 5.3 sends a message with an invalid for |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
jefflowrey wrote: |
portnovj007 wrote: |
However, WriteUTF function add 2 bytes to the beginning of the contents when it writes data to the MQSeries 5.3 queue. |
That's the byte order mark. I think you need that to be proper UTF. |
It's actually an integer that contains the length of the string written.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri May 06, 2005 10:47 am Post subject: Re: C# with MQSeries 5.3 sends a message with an invalid for |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
EddieA wrote: |
It's actually an integer that contains the length of the string written. |
 _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|