Sending Private Messages

Sending private messages requires setting the privacy level of the message, and, as an option, setting the privacy level of the queue where the message is sent, before the message is sent.

The properties used to set the privacy level of the message are the MSMQMessage object's PrivLevel and EncryptAlgorithm properties. The property used to set the privacy level of the queue is the MSMQQueueInfo object's PrivLevel property.

Note The actual call to send and read private messages is the same as the call to send and read non-private messages.

To send private messages
  1. Optional. Verify that the queue can receive private messages. The MSMQQueueInfo object's PrivLevel must be set to MQ_PRIV_LEVEL_BODY or MQ_PRIV_LEVEL_OPTIONAL. If set to MQ_PRIV_LEVEL_BODY, the queue can only accept private messages. Non-private messages will be ignored.
    qinfo.PrivLevel = MQ_PRIV_LEVEL_BODY
     
  2. Open the queue for sending messages.
    Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
    
  3. Set the MSMQMessage object's PrivLevel property to MQMSG_PRIV_LEVEL_BODY.
    msg.PrivLevel = MQMSG_PRIV_LEVEL_BODY
     
  4. Optional. Set the encryption algorithm used to encrypt the message.
    msg.EncryptAlgorithm = MQMSG_CALG_RC4
     
  5. Send the message.
    msg.Send q
     

Example

Dim qinfo As New MSMQQueueInfo
Dim q As New MSMQQueue
Dim msg As New MSMQMessage

Private Sub Form_Click()
  '**********************
  ' Create queue
  '**********************
  Set qinfo = New MSMQQueueInfo
  qinfo.PathName = ".\PrivacyTest"
  qinfo.Label = "Test Queue"
  qinfo.PrivLevel = MQ_PRIV_LEVEL_BODY
  qinfo.Create
  '*********************
  ' Open queue.
  '*********************
  Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
  '*********************
  ' Send message.
  '*********************
  msg.Label = "Test Message"
  msg.Body = "This is a private message."
  msg.PrivLevel = MQMSG_PRIV_LEVEL_BODY
  msg.EncryptAlgorithm = MQMSG_CALG_RC4
  msg.Send q
  MsgBox "The message " + msg.Label + " was sent."
  q.Close
  '*********************
  ' Receive message.
  '*********************
  Set q = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
  Set msg = q.Receive
  If msg.PrivLevel = MQMSG_PRIV_LEVEL_BODY Then
     MsgBox "Message " + msg.Label + " is private."
  Else
     MsgBox "Message " + msg.Label + " is not private."
  End If
  
   MsgBox "Encryption alogithm is: " + CStr(msg.EncryptAlgorithm)
   
   
End Sub
 

© 1997 by Microsoft Corporation. All rights reserved.