MQ

MQ

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Adding MQRFH2 headers to MQMessage in C#

  • 1.  Adding MQRFH2 headers to MQMessage in C#

    Posted Wed April 21, 2021 09:28 AM
    Hello! I need to send a MQMessage in .NET C# with specific JMS-Properties in the MQRFH2-header. The properties need to end up in the <ur>-tag for the target system to be able to use them properly. Because of this we can't use neither XMS nor SimpleMessageProperties. Any help would be greatly appreciated!

    ------------------------------
    Daniel Jonsson
    ------------------------------


  • 2.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu April 22, 2021 02:41 AM
    SimpleMessageProperties sample puts the properties under RFH folder as shown in picture below. Could you please let us know reason why you think SimpleMessageProperties does not suit your requirement? 

    Thank you


    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 3.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Mon April 26, 2021 03:09 AM
    Thanks for your reply. When we send a message using SimpleMessageProperties to our integration platform, it does not accept it giving an error that the field "JMSProperties" is missing. We have a working Java program that sets the properties directly onto a MQRFH2-header object and then writes it to the message, but I can't find a way to do that using C# .NET.

    ------------------------------
    Daniel Jonsson
    ------------------------------



  • 4.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Mon April 26, 2021 06:12 AM
    Thanks for clarifying. Unlike MQ Java, MQ .NET does not provide RFH2 classes. XMS .NET supports setting properties in a RFH2 folder. I know you mentioned XMS is not an option for you. I think you will have to build yourself the RFH2 header and required properties into the message using the various write methods of MQMessage class.

    Thanks
    Shashi

    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 5.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Tue April 27, 2021 02:29 AM
    I found an example from 2006 that I think does this, but the example has unfortunately been deleted so I can't check back on it. In Java you can do mqrfh2.write(mqmessage), but do you have any pointers on how to do the same in C#?

    The example I found uses a structure definition with MQRFH2-headers but I don't know how to use this with the MQMessage:
            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;
                }
            }​


    ------------------------------
    Daniel Jonsson
    ------------------------------



  • 6.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Wed September 11, 2024 10:35 AM

    Hello @Daniel Jonsson
    Did you managed to send and MQ message with RFH2 Headers with .NET application? If so, can you please share the code how you do that?

    Shashikanth, do we have any update on this topic? Is there any possibility to send MQ message with .net application that will include RFH2 header?

    Regards



    ------------------------------
    Bojan Bojan
    ------------------------------



  • 7.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 03:10 AM

    @Bojan Bojan I have reached out to other folks regarding this question. Will respond at the earliest. Thank you.



    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 8.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 04:57 PM

    Did you look at my answer here (scroll to #5):

    https://community.ibm.com/community/user/integration/discussion/c-classes-to-browse-embedded-header-from-mq-message-such-as-mqrfh-mqdead-etc

    later

    Roger



    ------------------------------
    Roger Lacroix
    CTO
    Capitalware Inc.
    London Canada
    https://capitalware.com
    ------------------------------



  • 9.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 01:25 AM

    Did you look at the specific JMS properties on MQRFH2 header?

    Like JMS message type (TextMessage vs BytesMessage etc...) Did you set those?



    ------------------------------
    Francois Brandelik
    ------------------------------



  • 10.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 03:42 AM

    Hello Francois

    I am trying to enter custom short XML that I have created into HRF2 Header, I have two of those XMLs and both of them need to go into the RFH2 header.
    I have tried to do that with .net code that I found on internet but I got MQRC_HEADER_ERROR exception.

    I don't know what are TextMessage vs BytesMessage in Java but I guess that are the functions for creating the messages, I use queueMessage.WriteString(message); and queueMessage.WriteBytes(message); in .Net

    after that I use this code to enter the RFH2 header:

    queueMessage.Write(rfh2Header);
    queueMessage.Format = MQC.MQFMT_RF_HEADER_2;
    For creating of the "rfh2Header" value I have tried several things that I found on internet but neither worked.
    If you can tell me how can I create the value of that header right with the XML that I have it would be perfect.
    I am looking forward to hearing from you.
    Regards


    ------------------------------
    Bojan Bojan
    ------------------------------



  • 11.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 08:16 AM

    The best way for you to understand what needs to be done is to write a little program in XMS .NET and populate the headers. Then use RFHUTIL(c) (github/ibm-messaging) to inspect the RFH2 header.

    You can then build the message using .NET only.



    ------------------------------
    Francois Brandelik
    ------------------------------



  • 12.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 09:03 AM

    a) The RFH2 is not something to hold arbitrary XML - no matter how short. It is purely for holding properties.

    b) There is very rarely any reason to construct an RFH2 in application code. Instead, use the Property APIs (setProperty in the .Net classes). Those are much simpler, and are equivalent and interchangeable. The receiving app will still see an RFH2 if it is setup that way.



    ------------------------------
    Mark Taylor
    Winchester
    ------------------------------



  • 13.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 09:09 AM

    Hello Mark

    Can you please give me example code of which .Net Class I need to use to set that property?

    Regards



    ------------------------------
    Bojan Bojan
    ------------------------------



  • 14.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Thu September 12, 2024 09:29 AM

    See the documentation at https://www.ibm.com/docs/en/ibm-mq/9.4?topic=interfaces-mqmessagenet-class



    ------------------------------
    Mark Taylor
    Winchester
    ------------------------------



  • 15.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Sat September 14, 2024 12:36 AM

    Hi @Mark Taylor,

    I wanted to ask about your statement above that says this:-

    a) The RFH2 is not something to hold arbitrary XML - no matter how short. It is purely for holding properties.

    This statement surprised me because I don't consider, as an example, items in the <psc> folder in an MQRFH2 to be message properties. In fact you are explicitly warned in IBM Docs not to set content='properties' on the <psc> folder (which would force it to be treated as message properties) because that would likely stop Message Broker from working.

    In fact the whole of that page in IBM Docs reads as if you can have any folder you like, and so long as it is not a recognised folder that MQ treats as properties, and you have not set content='properties' on folder, then the contents would very much not be treated as properties.

    Can you clarify this statement please?

    Cheers,
    Morag



    ------------------------------
    Morag Hughson
    MQ Technical Education Specialist
    MQGem Software Limited
    Website: https://www.mqgem.com
    ------------------------------



  • 16.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Tue February 04, 2025 02:38 PM

    Has anyone been able to do this successfully in .Net ? Please let me know



    ------------------------------
    Deepak Bharadwaj Aragola Muralidhar
    ------------------------------



  • 17.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Wed February 05, 2025 02:51 AM

    Hi Deepak 

    Yes, I have managed to insert the data in RFH2 header with .NET, if you were asking me.

    Do you need any help?

    Regards



    ------------------------------
    Bojan Bojan
    ------------------------------



  • 18.  RE: Adding MQRFH2 headers to MQMessage in C#

    Posted Wed February 05, 2025 11:07 PM

    Yes please. Can you please provide your code sample where you are setting the RFH2 header in MQMessage along with the actual message ?



    ------------------------------
    Deepak Bharadwaj Aragola Muralidhar
    ------------------------------