Message Body Types

 

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 body type of a message describes the format of the information in the message. For example, message bodies can contain simple integer and string formats as well as arrays and data record sets.

When designing applications, it is important that both the sending application and the receiving application understand what the format of the message body is. In general, it is the responsibility of the sending application to specify the message body type when sending messages and it is the responsibility of the receiving application to handle what ever message body type the sending application specified.

However, these responsibilities vary depending on whether the sending and receiving applications are making API function calls or COM component calls (note that because the sending application does not know what calls the receiving application will make, it is the developer's responsibility to test their sending applications against receiving applications that make API function calls and COM component calls). The following issues should be taken into consideration:

  • If the sending application call the MQSendMessage function to send messages, the application should always specify the body type. If the body type is not specified when the message is sent, Message Queuing sets the body type property to VT_EMPTY.

  • If the sending application calls the MSMQMessage.Send method, determines the body type of the message and sets the body type property for you.

  • If the receiving application calls the MQReceiveMessage or MQReceiveMessageByLookupId functions to read the messages, the receiving application should always check the body type before processing the body of the message. It is the responsibility of the receiving application to understand what type of message it is retrieving.

  • If the receiving application calls one of the peek or receive methods of the MSMQQueue object Message Queuing determines the message body type for you. However, if the message was sent using MQSendMessage, the following conditions can occur.

If the body type property was not set before MQSendMessage was called, the message body is treated as an array of bytes.

If the body type was set to an invalid body type (valid types are listed below) before MQSendMessage was called, the message can be retrieved but an error will occur when you try to read the message body.

If the body type of the message was not set by the sending application, the receiving application should assume that the message body is an array of bytes (the Message Queuing COM implementation does this automatically).

Message Body Type Property

The PROPID_M_BODY_TYPE property should be accessed only when you are using one of the following functions to send, peek at, or retrieve a message (as noted earlier, when using COM methods Message Queuing sets and retrieves this property for you):

When setting PROPID_M_BODY_TYPE, one of the defined body type values listed in the following table must be used. If an undefined type is used, problems may occur when an application using the COM components tries to read the body of the messages.

The following table lists all the valid body types.

Type Body contains
VT_EMPTY Default. Note that the Message Queuing COM implementation treats this value as an array of bytes.
VT_I1 A Char (1 byte) type.
VT_I2 A short integer.
VT_I4 A long integer.
VT_R4 A float (4-byte floating point).
VT_R8 A double-float (8-byte floating point).
VT_CY A CURRENCY type (8-byte).
VT_DATE An OLE DATE (8-byte) type.
VT_BSTR String data in Unicode (does not have to be NULL terminated).
VT_BOOL A VARIANT_BOOL (2-byte) type where -1 is TRUE and 0 is FALSE.
VT_UI1 A Char (1 byte) type. An array of bytes when joined by the OR operator with VT_ARRAY (VT_ARRAY | VT_UI1).
VT_UI2 A short integer.
VT_UI4 A long integer.
VT_LPSTR A variable-size, NULL-terminated ANSI string.
VT_LPWSTR A variable-size, NULL-terminated Unicode string.
VT_STREAMED_OBJECT A persistent, serialized object whose format is the output of a call to OleSaveToStream using IPersistStream.
VT_STORED_OBJECT A persistent serialized object whose format is the output of a call to OleSave using IPersistStorage.
VT_ARRAY | VT_UI1 An array of bytes.