PROPID_M_BODY

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

The PROPID_M_BODY property contains the body of the message.

Property ID

PROPID_M_BODY

Type Indicator

VT_VECTOR | VT_UI1

MQPROPVARIANT Field

caub

Property Value

Body of the message.

Remarks

Each Message Queuing message can have no more than 4 MB of data.

The body of the message can consist of any type of information. For example, message bodies can contain a simple string or a binary file with any internal structure. However, it is the responsibility of the sending and receiving applications to understand what type of body the message contains.

For information on how Message Queuing functions and COM methods handle different message body types, see Message Body Types.

The body type of the message is set by the PROPID_M_BODY_TYPE property (note that the body type is a separate message property, it is not set using the "type indicator" of the PROPID_M_BODY property). If the sending application does not set the PROPID_M_BODY_TYPE property, Message Queuing sets the body type to VT_EMPTY.

When retrieving messages, the receiving application should assume that the message is an array of bytes if it does not know what type of body the message contains. The Message Queuing COM implementation does this automatically for you.

When a message is sent to a URL-named queue over HTTP/HTTPS or to a multicast address, the message body is sent as a binary attachment to the SOAP envelope.

To set the body of a message, specify PROPID_M_BODY and PROPID_M_BODY_TYPE in the MQMSGPROPS structure and call MQSendMessage.

To retrieve the body of a message, specify PROPID_M_BODY_SIZE, PROPID_M_BODY_TYPE, and PROPID_M_BODY in the MQMSGPROPS structure. Then, call MQReceiveMessage or MQReceiveMessageByLookupId and examine the returned value.

If MQReceiveMessage or MQReceiveMessageByLookupId fails, returning an MQ_ERROR_BUFFER_OVERFLOW error, use the returned value of PROPID_M_BODY_SIZE to reallocate the message body buffer and call the applicable function again.

Before using the returned value of PROPID_M_BODY, always inspect the size and type of the body.

  • A returned PROPID_M_BODY_SIZE value of 0 indicates that no body was attached to the message.

  • A returned PROPID_M_BODY_TYPE value of VT_EMPTY indicates that the message type was not set (the Message Queuing COM implementation sets the body type for you when the message is sent).

When passing fixed-size messages between the sending and receiving application, and if this is the only type of message passed, you can allocate a fixed size buffer for receiving the message body without caring about the body size.

Equivalent COM Property

With COM components, the equivalent property is MSMQMessage.Body.

Example Code

The following code fragments show how PROPID_M_BODY is specified in arrays that can be used to initialize an MQMSGPROPS structure when setting and retrieving the message body:

To Send the Message Body

WCHAR wszMessageBody[] = L"Test Message.";  
aMsgPropID[i] = PROPID_M_BODY;                       // Property ID  
aMsgPropVar[i].vt = VT_VECTOR | VT_UI1;              // Type indicator  
aMsgPropVar[i].caub.pElems = (LPBYTE)wszMessageBody;  
aMsgPropVar[i].caub.cElems = sizeof(wszMessageBody);  
i++  
  
DWORD dwBodyType = VT_BSTR;  
aMsgPropID[i] = PROPID_M_BODY_TYPE;                  // Property ID  
aMsgPropVar[i].vt = VT_UI4;                          // Type indicator  
aMsgPropVar[i].ulVal = dwBodyType;  
i++  

To Retrieve the Message Body

aMsgPropID[i] = PROPID_M_BODY_SIZE;                  // Property ID  
aMsgPropVar[i].vt = VT_NULL;                         // Type indicator  
i++  
  
aMsgPropID[i] = PROPID_M_BODY_TYPE;                  // Property ID  
aMsgPropVar[i].vt = VT_NULL;                         // Type indicator  
i++  
  
ULONG ulBodyBufferSize = 1024;  
UCHAR * pucBodyBuffer = NULL;  
pucBodyBuffer = (UCHAR *)malloc(ulBodyBufferSize);  
if (pucBodyBuffer == NULL)  
{  
  return MQ_ERROR_INSUFFICIENT_RESOURCES;  
}  
memset(pucBodyBuffer, 0, ulBodyBufferSize);  
aMsgPropID[i] = PROPID_M_BODY;                       // Property ID  
aMsgPropVar[i].vt = VT_VECTOR | VT_UI1;              // Type indicator  
aMsgPropVar[i].caub.pElems = (UCHAR*)pucBodyBuffer;  
aMsgPropVar[i].caub.cElems = ulBodyBufferSize;  
i++  
  
// Reallocate memory for the body buffer if necessary.  
ulBodyBufferSize = aMsgPropVar[0].ulVal*sizeof(UCHAR);  
pucBodyBuffer = (UCHAR*)realloc(pucBodyBuffer, ulBodyBufferSize);  
if (pucBodyBuffer == NULL)  
{  
  return MQ_ERROR_INSUFFICIENT_RESOURCES;  
}  
memset(pucBodyBuffer, 0, ulBodyBufferSize);  
aMsgPropVar[2].caub.pElems = (UCHAR*)pucBodyBuffer;  // Pointer to the new buffer  
aMsgPropVar[2].caub.cElems = ulBodyBufferSize;       // New buffer size  

The following examples are included in Using Message Queuing.

For an example of See
Setting the message body when sending messages C/C++ Code Example: Sending Messages to a Destination Queue
Retrieving the body of a message C/C++ Code Example: Reading Messages Synchronously

See Also

Message Properties
MQMSGPROPS
MQReceiveMessage
MQReceiveMessageByLookupId
MQSendMessage
PROPID_M_BODY_SIZE
PROPID_M_BODY_TYPE