This example creates a customer XML document and sends it to the queue the Incoming Service monitors. This example requires references to the System.Messaging and Microsoft.Dynamics.GP.eConnect.Serialization assemblies.
Notice how the example performs the following steps:
Private Sub CreateCustomerSendtoMSMQ() Try 'XML document compnents Dim eConnect As New eConnectType Dim CustomerType As New SMCustomerMasterType Dim MyCustomer As New taUpdateCreateCustomerRcd 'Serialization objects Dim serializer As New XmlSerializer(GetType(eConnectType)) Dim MemStream As New MemoryStream Dim sCustomerXmlDoc As String 'Populate the MyCustomer object with data. With MyCustomer .CUSTNMBR = "JOEH0001" .CUSTNAME = "Joe Healy" .ADRSCODE = "PRIMARY" .ADDRESS1 = "789 First Ave N" .CITY = "Rollag" .STATE = "MN" .ZIPCODE = "23589" End With 'Build the XML document CustomerType.taUpdateCreateCustomerRcd = MyCustomer ReDim eConnect.SMCustomerMasterType(0) eConnect.SMCustomerMasterType(0) = CustomerType 'Serialize the XML document serializer.Serialize(MemStream, eConnect) MemStream.Position = 0 'Use the Memory Stream to create an xml string Dim xmlreader As New XmlTextReader(MemStream) While xmlreader.Read sCustomerXmlDoc = sCustomerXmlDoc & xmlreader.ReadOuterXml & vbCr End While 'Create the MSMQ queue and message objects Dim MyQueue As New MessageQueue(".\private$\econnect_incoming9") Dim MyMessage As New Message Dim MyQueTrans As New MessageQueueTransaction Dim MyFormatter As New ActiveXMessageFormatter 'Build the MSMQ message and send it to the queue MyMessage.Label = "eConnect Test with ActiveXMessageFormatter" MyMessage.Body = sCustomerXmlDoc MyMessage.Formatter = MyFormatter MyFormatter.Write(MyMessage, sCustomerXmlDoc) MyQueTrans.Begin() MyQueue.Send(MyMessage, MyQueTrans) MyQueTrans.Commit() MyQueue.Close() Catch ex As System.Exception Debug.Write(ex.Message & vbCrLf & ex.StackTrace) SerializedXmlDoc.Text = ex.Message & vbCrLf & ex.StackTrace End Try End Sub