Incoming Service example
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:
- Creates an eConnect serialization object for a customer and populates its elements with data.
- Creates an eConnect XML document that describes a new customer to add to Microsoft Dynamics GP.
- Serializes the eConnect XML document object to create a string representation of the XML.
- Specifies the MSMQ queue that will receive the message.
- Places the string representation of the XML document in an MSMQ message object.
- Sends the message to the specified queue.
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_incoming") 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