|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Problem with CCSID |
« View previous topic :: View next topic » |
Author |
Message
|
newbieMQ |
Posted: Fri Jul 24, 2015 2:25 am Post subject: Problem with CCSID |
|
|
Newbie
Joined: 24 Jul 2015 Posts: 3
|
Hello,
I am new to MQ. I am trying to put and get Messages with the MQ Client into a "Server". If I use amqsputc and amqsgetc everything works fine. When I am using a .NET program (C#) to send the Messages there is a Problem. When I get the message, the Server doesn't accept it and sends the original message back, but after each charater there is one character inserted (x'00'). The "Server" is requiring CCSID 923. I have set MQCCSID=923 in the Windows Environment, so it is already there after the PC has started. I also set 923 in the program code. I am stuck at this Point and I really hope someone here would be so nice to help me in this. Here is my code:
Code: |
queueName = tb_Queue.Text;
hostName = tb_Host.Text;
port = Convert.ToInt32(tb_Port.Text);
channelName = tb_Channel.Text;
queueManagerName = tb_QueueManager.Text;
numberOfMsgs = Convert.ToInt32(tb_AnzahlNachrichten.Text);
properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
properties.Add(MQC.CCSID_PROPERTY, 923);
Environment.SetEnvironmentVariable("MQCCSID", "923");
queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
message = new MQMessage();
StreamReader sr = new StreamReader(tb_Eingabedatei.Text, Encoding.GetEncoding("ISO-8859-15"));
messageString = sr.ReadToEnd();
sr.Close();
message.WriteString(messageString);
for (int i = 1; i <= numberOfMsgs; i++)
{
queue.Put(message,);
}
queue.Close();
queueManager.Disconnect(); |
Best regards
newbieMQ |
|
Back to top |
|
 |
Vitor |
Posted: Fri Jul 24, 2015 4:23 am Post subject: Re: Problem with CCSID |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
newbieMQ wrote: |
When I am using a .NET program (C#) to send the Messages there is a Problem. When I get the message, the Server doesn't accept it and sends the original message back, but after each charater there is one character inserted (x'00'). The "Server" is requiring CCSID 923. I have set MQCCSID=923 in the Windows Environment, so it is already there after the PC has started. I also set 923 in the program code. |
.NET uses double byte Unicode for it's strings, irrespective of the underlying CCSID. So when you say:
Code: |
message.WriteString(messageString); |
it does exactly that. The extra X'00' is because CCSID 923 is a single byte character set and hence, when converted to double byte, the second byte is always zero. The sample amqsgetc & amqsputc are C programs that honour the underlying system CCSID and that's why they work.
If you search this forum you'll find a wealth of discussion and advice on this. You're not the first person .NET has caught like this and I doubt you'll be the last. _________________ Honesty is the best policy.
Insanity is the best defence.
Last edited by Vitor on Fri Jul 24, 2015 4:38 am; edited 1 time in total |
|
Back to top |
|
 |
newbieMQ |
Posted: Fri Jul 24, 2015 4:33 am Post subject: |
|
|
Newbie
Joined: 24 Jul 2015 Posts: 3
|
Thanks a lot Vitor for the Explanation.
I will search the Forum for this.
Cheers! |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Jul 24, 2015 5:47 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
There should be .NET methods of converting the message data to a different CCSID before you stick it into the message.
Or maybe there's another option on WriteString? |
|
Back to top |
|
 |
Vitor |
Posted: Fri Jul 24, 2015 6:04 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mqjeff wrote: |
There should be .NET methods of converting the message data to a different CCSID before you stick it into the message.
Or maybe there's another option on WriteString? |
I think there are both, but I'm not enough of a .NET person to reliably comment. Hence I thought it's best if the OP does their own research after I point in generally the right direction. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
vsathyan |
Posted: Fri Jul 24, 2015 10:42 am Post subject: |
|
|
Centurion
Joined: 10 Mar 2014 Posts: 121
|
Before posting message to the queue, set the message property as below
message.CharacterSet = 1208; //UTF8
message.Format = MQC.MQFMT_STRING;
and then put the message.
While reading,
do the same, it should work.
Thanks,
vsathyan _________________ Custom WebSphere MQ Tools Development C# & Java
WebSphere MQ Solution Architect Since 2011
WebSphere MQ Admin Since 2004 |
|
Back to top |
|
 |
newbieMQ |
Posted: Sun Jul 26, 2015 11:53 pm Post subject: |
|
|
Newbie
Joined: 24 Jul 2015 Posts: 3
|
Many thanks to everyone for the provided help. I got it working. I added two lines after "message = new MQMessage();"
Code: |
queueName = tb_Queue.Text;
hostName = tb_Host.Text;
port = Convert.ToInt32(tb_Port.Text);
channelName = tb_Channel.Text;
queueManagerName = tb_QueueManager.Text;
numberOfMsgs = Convert.ToInt32(tb_AnzahlNachrichten.Text);
properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
properties.Add(MQC.CCSID_PROPERTY, 923);
Environment.SetEnvironmentVariable("MQCCSID", "923");
queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
message = new MQMessage();
message.CharacterSet = 923;
message.Format = MQC.MQFMT_STRING;
StreamReader sr = new StreamReader(tb_Eingabedatei.Text, Encoding.GetEncoding("ISO-8859-15"));
messageString = sr.ReadToEnd();
sr.Close();
message.WriteString(messageString);
for (int i = 1; i <= numberOfMsgs; i++)
{
queue.Put(message,);
}
queue.Close();
queueManager.Disconnect(); |
Regards
newbieMQ |
|
Back to top |
|
 |
vsathyan |
Posted: Mon Jul 27, 2015 10:54 am Post subject: |
|
|
Centurion
Joined: 10 Mar 2014 Posts: 121
|
I'm glad you did it.  _________________ Custom WebSphere MQ Tools Development C# & Java
WebSphere MQ Solution Architect Since 2011
WebSphere MQ Admin Since 2004 |
|
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
|
|
|
|