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:

  1. Specify the MSMQ destination.

    Create a message queue object and specify the eConnect incoming queue. The Incoming Service uses the private queue named eConnect_incoming9. The following Visual Basic .NET code creates the object and specifies the eConnect_incoming9queue on the local server:

    Dim MyQueue As New MessageQueue(".\private$\econnect_incoming9")
    
    
    1. 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.

      1. 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)
        
        
        1. Use a queue transaction.

          The eConnect_incoming9is 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_incoming9queue:

          Dim MyQueTrans As New MessageQueueTransaction
          MyQueTrans.Begin()
          	MyQueue.Send(MyMessage, MyQueTrans)
          MyQueTrans.Commit()
          
          
          1. 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.