Topic
  • 4 replies
  • Latest Post - ‏2013-04-26T03:19:56Z by GBaddeley
LI.YG
LI.YG
14 Posts

Pinned topic MQ7. put from C# and get from C++

‏2013-04-25T08:46:48Z |

Hi,

I got a question on the sample code from IBM. I created 2 vs projects: 1 for nmqsput.cs and 1 for imqsget.cpp. I tried to send a message from the C# program and receive it from the C++ program. Say the message is "hello". After calling queue.get( msg, gmo ), the buffer contains a char array like this: ['h', 0, 'e', 0, 'l', 0, 'l', 0, 'o', 0...]. Seems it is a message encoding issue, but I could not find any solution for it. Any suggestions are appreciated very much.

(corrected the title of this post)

cheers,

YG

Updated on 2013-04-26T02:44:18Z at 2013-04-26T02:44:18Z by LI.YG
  • GBaddeley
    GBaddeley
    302 Posts
    ACCEPTED ANSWER

    Re: MQ7. put from C++ and get from C#

    ‏2013-04-25T23:20:13Z  

    You are either putting the message using a double byte character set, or when getting it, the message is being converted to a double byte character set, or the C++ program is using double bytes as its native string representation and you are looking at the array as though it were single byte characters.

    Use MQ Explorer or some other tool to check the CodedCharSetId and data of the message after it has as been sent and is sitting on the queue (before you receive it).

     

    HTH, G.

  • LI.YG
    LI.YG
    14 Posts
    ACCEPTED ANSWER

    Re: MQ7. put from C++ and get from C#

    ‏2013-04-26T02:59:58Z  
    • LI.YG
    • ‏2013-04-26T02:42:45Z

    Hi GBaddeley,

    Thanks a lot for the reply.

     

    It is the C# program that puts messages using double byte char set. The MessageLength = 10 for the "hello" message. Should I solve this issue by modifying the program or change some settings in the MQ server?

     

    Both the C# program and the C++ program are sample tools provided by IBM. My understanding is that different applications exchange data/messages via MQ. So developers should not explicitly parse the an input message by assuming 1 byte char or 2 byte char is used. I tried to change some general properties in the program, but they seem to be irrelevant to this issue:

    mqMsg.CharacterSet = MQC.MQCCSI_Q_MGR;

    mqMsg.Format = MQC.MQFMT_STRING;

    And both C# and C++ are using 546 encoding (mqMsg.Encoding).

     

    I don't have access to the MQ server. Is there anything I can ask my SA to change in the settings?

     

    cheers,

    YG

    Hi GBaddeley,

    I tried to this and it works now.

    mqMsg.CharacterSet = 437;

    Thanks.

     

    cheers,

    YG

  • GBaddeley
    GBaddeley
    302 Posts
    ACCEPTED ANSWER

    Re: MQ7. put from C++ and get from C#

    ‏2013-04-26T03:19:56Z  
    • LI.YG
    • ‏2013-04-26T02:42:45Z

    Hi GBaddeley,

    Thanks a lot for the reply.

     

    It is the C# program that puts messages using double byte char set. The MessageLength = 10 for the "hello" message. Should I solve this issue by modifying the program or change some settings in the MQ server?

     

    Both the C# program and the C++ program are sample tools provided by IBM. My understanding is that different applications exchange data/messages via MQ. So developers should not explicitly parse the an input message by assuming 1 byte char or 2 byte char is used. I tried to change some general properties in the program, but they seem to be irrelevant to this issue:

    mqMsg.CharacterSet = MQC.MQCCSI_Q_MGR;

    mqMsg.Format = MQC.MQFMT_STRING;

    And both C# and C++ are using 546 encoding (mqMsg.Encoding).

     

    I don't have access to the MQ server. Is there anything I can ask my SA to change in the settings?

     

    cheers,

    YG

    >It is the C# program that puts messages using double byte char set. The MessageLength = 10 for the "hello" message.

    > Should I solve this issue by modifying the program or change some settings in the MQ server?

    You could modify the program so that it puts a SBCS string into the message buffer, to match the default SBCS char set id being used by the MQ app, or to set the char set id on the put to an appropriate DBCS char set id.

    Glad to see you got it to work.  Character set issues are usually resolved by the apps setting the correct char set id to match what they store in the message data (if this differs from the queue manager default char set id).

    If MQ is doing conversion, the receiving queue manager needs to support conversion between the two char set ids being used on the put and get.

    If the apps are using the queue managers default char set ids, the apps needs to ensure that the message data is correct for this char set id. There is a classic case on z/OS mainframe where the qmgr default char set id is 500 (international EBCDIC) but the app puts or gets data assuming it is 37 (IBM-US EBCDIC). There are a few special characters that are not the same in these char sets!

    99% of the time apps just use the defaults and no issues arise...

    HTH, G.

     

  • GBaddeley
    GBaddeley
    302 Posts

    Re: MQ7. put from C++ and get from C#

    ‏2013-04-25T23:20:13Z  

    You are either putting the message using a double byte character set, or when getting it, the message is being converted to a double byte character set, or the C++ program is using double bytes as its native string representation and you are looking at the array as though it were single byte characters.

    Use MQ Explorer or some other tool to check the CodedCharSetId and data of the message after it has as been sent and is sitting on the queue (before you receive it).

     

    HTH, G.

  • LI.YG
    LI.YG
    14 Posts

    Re: MQ7. put from C++ and get from C#

    ‏2013-04-26T02:42:45Z  
    • GBaddeley
    • ‏2013-04-25T23:20:13Z

    You are either putting the message using a double byte character set, or when getting it, the message is being converted to a double byte character set, or the C++ program is using double bytes as its native string representation and you are looking at the array as though it were single byte characters.

    Use MQ Explorer or some other tool to check the CodedCharSetId and data of the message after it has as been sent and is sitting on the queue (before you receive it).

     

    HTH, G.

    Hi GBaddeley,

    Thanks a lot for the reply.

     

    It is the C# program that puts messages using double byte char set. The MessageLength = 10 for the "hello" message. Should I solve this issue by modifying the program or change some settings in the MQ server?

     

    Both the C# program and the C++ program are sample tools provided by IBM. My understanding is that different applications exchange data/messages via MQ. So developers should not explicitly parse the an input message by assuming 1 byte char or 2 byte char is used. I tried to change some general properties in the program, but they seem to be irrelevant to this issue:

    mqMsg.CharacterSet = MQC.MQCCSI_Q_MGR;

    mqMsg.Format = MQC.MQFMT_STRING;

    And both C# and C++ are using 546 encoding (mqMsg.Encoding).

     

    I don't have access to the MQ server. Is there anything I can ask my SA to change in the settings?

     

    cheers,

    YG

  • LI.YG
    LI.YG
    14 Posts

    Re: MQ7. put from C++ and get from C#

    ‏2013-04-26T02:59:58Z  
    • LI.YG
    • ‏2013-04-26T02:42:45Z

    Hi GBaddeley,

    Thanks a lot for the reply.

     

    It is the C# program that puts messages using double byte char set. The MessageLength = 10 for the "hello" message. Should I solve this issue by modifying the program or change some settings in the MQ server?

     

    Both the C# program and the C++ program are sample tools provided by IBM. My understanding is that different applications exchange data/messages via MQ. So developers should not explicitly parse the an input message by assuming 1 byte char or 2 byte char is used. I tried to change some general properties in the program, but they seem to be irrelevant to this issue:

    mqMsg.CharacterSet = MQC.MQCCSI_Q_MGR;

    mqMsg.Format = MQC.MQFMT_STRING;

    And both C# and C++ are using 546 encoding (mqMsg.Encoding).

     

    I don't have access to the MQ server. Is there anything I can ask my SA to change in the settings?

     

    cheers,

    YG

    Hi GBaddeley,

    I tried to this and it works now.

    mqMsg.CharacterSet = 437;

    Thanks.

     

    cheers,

    YG

  • GBaddeley
    GBaddeley
    302 Posts

    Re: MQ7. put from C++ and get from C#

    ‏2013-04-26T03:19:56Z  
    • LI.YG
    • ‏2013-04-26T02:42:45Z

    Hi GBaddeley,

    Thanks a lot for the reply.

     

    It is the C# program that puts messages using double byte char set. The MessageLength = 10 for the "hello" message. Should I solve this issue by modifying the program or change some settings in the MQ server?

     

    Both the C# program and the C++ program are sample tools provided by IBM. My understanding is that different applications exchange data/messages via MQ. So developers should not explicitly parse the an input message by assuming 1 byte char or 2 byte char is used. I tried to change some general properties in the program, but they seem to be irrelevant to this issue:

    mqMsg.CharacterSet = MQC.MQCCSI_Q_MGR;

    mqMsg.Format = MQC.MQFMT_STRING;

    And both C# and C++ are using 546 encoding (mqMsg.Encoding).

     

    I don't have access to the MQ server. Is there anything I can ask my SA to change in the settings?

     

    cheers,

    YG

    >It is the C# program that puts messages using double byte char set. The MessageLength = 10 for the "hello" message.

    > Should I solve this issue by modifying the program or change some settings in the MQ server?

    You could modify the program so that it puts a SBCS string into the message buffer, to match the default SBCS char set id being used by the MQ app, or to set the char set id on the put to an appropriate DBCS char set id.

    Glad to see you got it to work.  Character set issues are usually resolved by the apps setting the correct char set id to match what they store in the message data (if this differs from the queue manager default char set id).

    If MQ is doing conversion, the receiving queue manager needs to support conversion between the two char set ids being used on the put and get.

    If the apps are using the queue managers default char set ids, the apps needs to ensure that the message data is correct for this char set id. There is a classic case on z/OS mainframe where the qmgr default char set id is 500 (international EBCDIC) but the app puts or gets data assuming it is 37 (IBM-US EBCDIC). There are a few special characters that are not the same in these char sets!

    99% of the time apps just use the defaults and no issues arise...

    HTH, G.