Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This example retrieves an MSMQ message from the Outgoing Service queue. This example requires references to the System.Messaging and System.XML assemblies.
Notice how the example performs the following steps:
- Creates a MessageQueue object to access the Outgoing Service's message queue.
- Creates the MSMQ Formatter, MessageQueueTransaction, and Message objects.
- Retrieves the message from the queue.
- Retrieves the string from the Message object
- Loads the string into an XML document object and uses it to display the XML in a textbox. To allow access to specific XML elements and values, the example parses the string into XML. Refer to the .NET Framework documentation for information about creating XML from a string.
Private Sub GetMessage()
'Create queue object to retrieve messages from the default outgoing queue
Dim MyQueue As New MessageQueue(".\private$\econnect_outgoing")
'Create an MSMQ formatter and transaction objects
MyQueue.Formatter = New ActiveXMessageFormatter
Dim MyTransaction As New MessageQueueTransaction
'Create a message object
Dim MyMessage As Message
Try
'Retrieve a message from the queue
'This example assumes there is always a message waiting in the queue
MyTransaction.Begin()
MyMessage = MyQueue.Receive(MyTransaction)
MyTransaction.Commit()
'Retrieve the string from the message
Dim MyDocument As [String] = CType(MyMessage.Body, [String])
'Load the string into an XML document object
Dim MyXml As New XmlDocument
MyXml.LoadXml(MyDocument)
'Display the XML from the queue message
MessageText.Text = MyXml.InnerXml
Catch err As SystemException
ErrorText.Text = err.InnerException.ToString()
End Try
End Sub