Using channel exits in IBM WebSphere MQ .NET

If you use client bindings, you can use channel exits as for any other client connection. If you use managed bindings, you must write an exit program that implements an appropriate interface.

Client bindings

If you use client bindings, you can use channel exits as described in Channel exits. You cannot use channel exits written for managed bindings.

Managed bindings

If you use a managed connection, to implement an exit, you define a new .NET class that implements the appropriate interface. Three exit interfaces are defined in the WebSphere® MQ package:
  • MQSendExit
  • MQReceiveExit
  • MQSecurityExit
Note: User exits written using these interfaces are not supported as channel exits in the unmanaged environment.
The following sample defines a class that implements all three:

class MyMQExits : MQSendExit, MQReceiveExit, MQSecurityExit 
{
   // This method comes from the send exit
  byte[] SendExit(MQChannelExit       channelExitParms,
                  MQChannelDefinition channelDefinition,
                  byte[]              dataBuffer
                  ref int             dataOffset
                  ref int             dataLength
                  ref int             dataMaxLength)
  {
     // complete the body of the send exit here
  }
 
 
  // This method comes from the receive exit
  byte[] ReceiveExit(MQChannelExit       channelExitParms,
                     MQChannelDefinition channelDefinition,
                     byte[]              dataBuffer
                     ref int             dataOffset
                     ref int             dataLength
                     ref int             dataMaxLength)
  {
     // complete the body of the receive exit here
  }
 
 
  // This method comes from the security exit
  byte[] SecurityExit(MQChannelExit       channelExitParms,
                      MQChannelDefinition channelDefParms,
                      byte[]              dataBuffer
                      ref int             dataOffset
                      ref int             dataLength
                      ref int             dataMaxLength)
  {
     // complete the body of the security exit here
  }
 
}

Each exit is passed an MQChannelExit and an MQChannelDefinition object instance. These objects represent the MQCXP and MQCD structures defined in the procedural interface.

The data to be sent by a send exit, and the data received in a security or receive exit is specified using the exit's parameters.

On entry, the data at offset dataOffset with length dataLength in the byte array dataBuffer is the data that is about to be sent by a send exit, and the data received in a security or receive exit. The parameter dataMaxLength gives the maximum length (from dataOffset) available to the exit in dataBuffer. Note: For a security exit, it is possible for the dataBuffer to be null, if this is the first time the exit is called or the partner end elected to send no data.

On return, the value of dataOffset and dataLength should be set to point to the offset and length within the returned byte array that the .NET classes should then use. For a send exit, this indicates the data that it should send, and for a security or receive exit, the data that should be interpreted. The exit should normally return a byte array; exceptions are a security exit which could elect to send no data, and any exit called with the INIT or TERM reasons. The simplest form of exit that can be written therefore is one which does nothing more than return dataBuffer:

The simplest possible exit body is:

{
  return dataBuffer;
}

MQChannelDefinition class

[V7.5.0.6 Mar 2016]From Version 7.5.0, Fix Pack 6, the userid and password that are specified with the managed .NET client application are set in the IBM® WebSphere MQ .NET MQChannelDefinition class that is passed to the client security exit. The security exit copies the userid and password into the MQCD.RemoteUserIdentifier and MQCD.RemotePassword fields (see Writing a security exit).