How to put a binary File in Websphere MQ

Posted on 2008-10-07
Last Modified: 2013-12-11

I am new to MQ. I am using the attached program to put a Text message in the Websphere MQ in C#. Now I need to put a binary file to the Remote Queue. How can I do that? Any code sample available?


using System;
using IBM.WMQ;
public class MQSample1
    private String qManager = "QMQB01"; //define name of queue
    //manager to connect to.
    private MQQueueManager qMgr;  //define a queue manager object
    static void Main(string[] args)
        new MQSample1();
    public MQSample1()
            //Create a connection to the queue manager
            qMgr = new MQQueueManager(qManager);
            //Set up the options on the queue we wish to open...
            //Note.All WebSphere MQ Options are prefixed with MQC
            int openOptions =  MQC.MQOO_OUTPUT;
            //MQC.MQOO_INPUT_AS_Q_DEF |
            //Now specify the queue that we wish to open,
            //and the open options...
            MQQueue system_default_local_queue = qMgr.AccessQueue("Q.EZL01.SEP.CMCC.001.S1", openOptions);
            //Define a simple WebSphere MQ message,and write some text in UTF format..
            MQMessage hello_world = new MQMessage();
            hello_world.WriteUTF("Hello World!");
            //specify the message options...
            MQPutMessageOptions pmo = new MQPutMessageOptions(); //accept the defaults,
            //same as MQPMO_DEFAULT
            //put the message on the queue
            system_default_local_queue.Put(hello_world, pmo);
            //Close the queue...
            //Disconnect from the queue manager
        //If an error has occurred in the above,try to identify what went wrong
        //Was it a WebSphere MQ error?
        catch (MQException ex)
            Console.WriteLine("A WebSphere MQ error occurred :Completion code " +
            ex.CompletionCode + "Reason code " + ex.ReasonCode);
        //Was it a System error?
        catch (System.Exception ex)
            Console.WriteLine("A System error occurred:" + ex);
}//end of sample

Open in new window

Question by:kakali
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 22666422
Is there any expert to help me in this problem please.............

Accepted Solution

lgacs earned 250 total points
ID: 22667655
1) Use
   hello_world.write( byte[] );
instead of
    hello_world.WriteUTF("Hello World!");

2) Set the FORMAT field in MQMD to 'MQC.MQFMT_NONE' (8 spaces).
   hello_world.format = MQC.MQFMT_NONE;

Author Comment

ID: 22675569
Many thanks. Yes I can now upload the binary file. But I need to set some property which is not the MQ Default property. I have some code example where the JMS is used to set these properties but I need to set these property as well. How can I set those property ?

MQQueueConnectionFactory factory = new MQQueueConnectionFactory();
qConn = factory.createQueueConnection("qbuser", "password");
qSession = qConn.createQueueSession(false, 1);
MQQueue q = new MQQueue("Q.EZL01.SEP.CMCC.001.02");
sender = qSession.createSender(q);
BytesMessage msg = qSession.createBytesMessage();
msg.setStringProperty("FILENAME", filename);
msg.setStringProperty("BLOB_ID", blobID);
As in the above code I also have to set those two property "FILENAME" & "BLOBID". How can I set those property using MQMessage in C#.

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question