PRB: MSMQMessage Object IsAuthenticated Property Returns an Integer
ID: Q246218
|
The information in this article applies to:
-
Microsoft Message Queue Server versions 1.0, 2.0
SYMPTOMS
The IsAuthenticated property of a Microsoft Message Queue (MSMQ) MSMQMessage object returns an Integer result rather than a Boolean result. IsOpen returns a 1 if the message is authenticated and a 0 if it is not. This can cause logic errors in a Visual Basic (VB) program if the property is used in the expression portion of an If, While, or similar conditional statement.
When a numeric value is used in a condition statement in VB, 0 is evaluated as false and all non-zero values are evaluated as true. The Not operator in VB inverts the bits of a value when used on a numeric value. The expression "Not 1" produces the result "-2" which is considered a "true" value in a VB condition statement.
Since VB evaluates both "1" and "Not 1" as true statements, if a queue is open both "message.IsAuthenticated" and "Not message.IsAuthenticated" evaluates true. In the following example code, if the message is authenticated both message boxes appear:
If message.IsAuthenticated Then
MsgBox "The message is authenticated."
End If
If Not message.IsAuthenticated Then
MsgBox "The message is not authenticated"
End If
RESOLUTION
There are two possible workarounds for the problem:
-
Explicitly test the value of the IsAuthenticated property against 0 and 1. A value of 1 indicates that the message is authenticated, a value of 0 indicates that the message is not authenticated. An example of this test is shown in the following code:
If MSMQMessageObject.IsAuthenticated = 1 Then
MsgBox "The message is authenticated."
End If
If MSMQMessageObject.IsAuthenticated = 0 Then
MsgBox "The message is not authenticated"
End If
-
Avoid "negative" tests that use the Not operator with the IsAuthenticated property.
STATUS
It is safe to test explicitly for the 1 and 0 values. These values will not be changed in any future version of MSMQ and will remain consistent.
Future versions of the MSMQ ActiveX components may add a property that may be evaluated as a true Boolean type for testing this characteristic.
MORE INFORMATION
The MSDN Online help describes the return values for the IsAuthenticated property as follows:
MSMQMessage.IsAuthenticated
Returned Value
1
The sending application requested authentication. The receiving Queue
Manager authenticated the message when it received the message.
0
The sending application did not request authentication. The receiving
Queue Manager did not attempt to authenticate the message when it
received the message.
REFERENCES
MSDN Online help for the MSMQMessage object type.
Visual Basic Programmers Guide
Q246222 MSMQQueueInfo Object IsTransactional Property Returns An Integer
Q245753 MSMQQueue Object IsOpen Property Returns an Integer
Q246225 MSMQQueueInfo Object IsWorldReadable Property Returns and Integer
Q246458 MSMQMessage Object IsFirstInTransaction Property Returns An Integer
Q246460 MSMQMessage Object IsLastInTransaction Property Returns An Integer
Additional query words:
MSMQ MSMQMessage IsAuthenticated
Keywords : kbMSMQ kbMSMQ100 kbMSMQ100bug kbDSupport
Version : winnt:1.0,2.0
Platform : winnt
Issue type : kbprb