Creating an MSMQ message
To use MSMQ, add a reference to the System.Messaging assembly of the .NET framework. To send your XML document to the queue, complete the following steps:
Specify the MSMQ destination.
Create a message queue object and specify the eConnect incoming queue. The Incoming Service uses the private queue named eConnect_incoming. The following Visual Basic .NET code creates the object and specifies the eConnect_incoming queue on the local server:
Dim MyQueue As New MessageQueue(".\private$\econnect_incoming")
Populate an MSMQ message.
Create a message object. The following example creates a message object, and then populates the label and message body properties:
Dim MyMessage As New Message
MyMessage.Label = "eConnect Test with ActiveXMessageFormatter" MyMessage.Body = sCustomerXmlDoc
Notice how the string representation of the XML document is used to populate the message body.
Specify the message format.
Create a message formatter object to specify how to serialize and deserialize the message body. The following sample uses an ActiveXMessageFormatter:
Dim MyFormatter As New ActiveXMessageFormatter
MyMessage.Formatter = MyFormatter MyFormatter.Write(MyMessage, sCustomerXmlDoc)
Use a queue transaction.
The eConnect_incoming is a transactional queue. A transactional queue requires a MesssageQueueTransaction object. The following Visual Basic .NET code shows how to create and use MesssageQueueTransaction to send a message to the eConnect_incoming queue:
Dim MyQueTrans As New MessageQueueTransaction
MyQueTrans.Begin() MyQueue.Send(MyMessage, MyQueTrans) MyQueTrans.Commit()
Close the queue connection.
Once the message is sent, close the queue object. The following sample closes the queue and frees its resources.
MyQueue.Close()
Refer to the System.Messaging documentation of the .NET Framework for additional information about message queue classes and enumerations.