Share via


eConnectOut serialization example

To request data using eConnect, you must create an XML document that describes the data you want to retrieve. The <eConnectOut> XML node gives you the ability to query Microsoft Dynamics GP using eConnect's XML-based syntax.

The following Visual Basic .NET example uses the eConnectOut class from the Microsoft.Dyanmics.GP.eConnect.Serialization namespace to request the complete customer document for a specified customer record.

As you review the example, note the following actions:

  • The request begins with the creation of an eConnectOut object. The values in the object's elements describe the single customer document to retrieve.
  • The value of the OUTPUTTYPE element instructs eConnect to return the customer master document.
  • The values in the INDEX1FROM and INDEX1TO elements specify the customer ID.
  • The values in the FORLIST and FORLOAD elements instruct eConnect to return the XML document directly to the caller.
  • The example populates the eConnectOut property of the <RQeConnectOutType> transaction type object with the eConnectOut object.
  • To complete the eConnect XML document, the RQeConnectOutType object populates the eConnect document's RQeConnectOutType property.
  • The XMLSerializer object converts the XML document object to a string.
  • The next step creates an eConnectMethods object and calls its eConnect_Requester method. Notice how the string representation of the eConnect XML document is the method's third parameter. Refer to eConnect Assembly for additional information about the eConnectMethods class and the eConnect_Requester method.
  • The result of the eConnect_Requester method is written to a file named "Customer.xml".

The following Visual Basic .NET code performs the prescribed actions:

Imports System
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO
Imports System.EnterpriseServices
Imports System.Text
Imports Microsoft.Dynamics.GP.eConnect
Imports Microsoft.Dynamics.GP.eConnect.Serialization
Module Module1
    Sub Main()
        Dim serializer As New XmlSerializer(GetType(eConnectType))
        Dim eConnect As New eConnectType()
        Dim eConnectouttype As New RQeConnectOutType()
        Dim eConnectOut As New eConnectOut()
        Dim entrypoint As New eConnectMethods()
        Dim requesterDoc As String
        Dim sConnectionString As String
        Try
            'Populate the eConnectOut object to specify the data request
            With eConnectOut
                .DOCTYPE = "Customer"
                .OUTPUTTYPE = 1
                .INDEX1FROM = "AARONFIT0001"
                .INDEX1TO = "AARONFIT0001"
                .FORLIST = 1
            End With
            'Create an XML document for the request
            eConnectouttype.eConnectOut = eConnectOut
            ReDim Preserve eConnect.RQeConnectOutType(0)
            eConnect.RQeConnectOutType(0) = eConnectouttype
            'Serialize the eConnect object to a memory stream
            Dim memStream As New MemoryStream()
            serializer.Serialize(memStream, eConnect)
            memStream.Position = 0
            'Use the memory stream to load an Xml document
            Dim xmlDoc As New XmlDocument()
            xmlDoc.Load(memStream)
            memStream.Close()
            'Create a connection string to Microsoft Dynamics GP
            sConnectionString = "data source=MyServer;" _
                & "initial catalog=TWO; integrated security=SSPI;" _
                & "persist security info=False; packet size=4096"
            'Request the data from the server
            requesterDoc = entrypoint.eConnect_Requester(sConnectionString, _
                EnumTypes.ConnectionStringType.SqlClient, xmlDoc.OuterXml)
            'Write the customer XML to a file
            Dim fs As New FileStream("Customer.xml", FileMode.Create)
            Dim writer As New StreamWriter(fs, New UTF8Encoding)
            writer.Write(requesterDoc)
            writer.Close()
        Catch exp As eConnectException
            Debug.Write(exp.ToString)
        Catch ex As System.Exception
            Debug.Write(ex.Message & vbCrLf & ex.StackTrace)
        End Try
    End Sub
End Module

When the application runs, the eConnect_Requester method returns a string that is assigned to the requesterDoc variable. The requesterDoc string contains the following XML:

<root>
    <eConnect ACTION="0" Requester_DOCTYPE="Customer" DBNAME="TWO"
    TABLENAME="RM00101" DATE1="1900-01-01T00:00:00" CUSTNMBR="AARONFIT0001">
        <Customer>
            <CUSTNMBR>AARONFIT0001</CUSTNMBR>
            <ADDRESS1>One Microsoft Way</ADDRESS1>
            <ADDRESS2 />
            <ADDRESS3 />
            <ADRSCODE>PRIMARY</ADRSCODE>
            <CITY>Redmond</CITY>
            <CNTCPRSN>Bob Fitz</CNTCPRSN>
            <COUNTRY>USA</COUNTRY>
            <CPRCSTNM />
            <CURNCYID>Z-US$</CURNCYID>
            <CUSTCLAS>USA-ILMO-T1</CUSTCLAS>
            <CUSTDISC>0</CUSTDISC>
            <CUSTNAME>Aaron Fitz Electrical</CUSTNAME>
            <PHONE1>42555501010000</PHONE1>
            <PHONE2>00000000000000</PHONE2>
            <PHONE3 />
            <FAX>31255501010000</FAX>
            <PYMTRMID>Net 30</PYMTRMID>
            <SALSTERR>TERRITORY 1</SALSTERR>
            <SHIPMTHD>LOCAL DELIVERY</SHIPMTHD>
            <SLPRSNID>PAUL W.</SLPRSNID>
            <STATE>WA</STATE>
            <TAXSCHID>USASTCITY-6*</TAXSCHID>
            <TXRGNNUM />
            <UPSZONE />
            <ZIP>98052-6399</ZIP>
            <STMTNAME>Aaron Fitz Electrical</STMTNAME>
            <SHRTNAME>Aaron Fitz Elec</SHRTNAME>
            <PRBTADCD>PRIMARY</PRBTADCD>
            <PRSTADCD>WAREHOUSE</PRSTADCD>
            <STADDRCD>PRIMARY</STADDRCD>
            <CHEKBKID>UPTOWN TRUST</CHEKBKID>
            <CRLMTTYP>2</CRLMTTYP>
            <CRLMTAMT>35000.00000</CRLMTAMT>
            <CRLMTPER>0</CRLMTPER>
            <CRLMTPAM>0.00000</CRLMTPAM>
            <RATETPID />
            <PRCLEVEL />
            <MINPYTYP>0</MINPYTYP>
            <MINPYDLR>0.00000</MINPYDLR>
            <MINPYPCT>0</MINPYPCT>
            <FNCHATYP>1</FNCHATYP>
            <FNCHPCNT>150</FNCHPCNT>
            <FINCHDLR>0.00000</FINCHDLR>
            <MXWOFTYP>2</MXWOFTYP>
            <MXWROFAM>25.00000</MXWROFAM>
            <COMMENT1 />
            <COMMENT2 />
            <USERDEF1>Retail</USERDEF1>
            <USERDEF2 />
            <TAXEXMT1 />
            <TAXEXMT2 />
            <BALNCTYP>0</BALNCTYP>
            <STMTCYCL>5</STMTCYCL>
            <BANKNAME />
            <BNKBRNCH />
            <FRSTINDT>1900-01-01T00:00:00</FRSTINDT>
            <INACTIVE>0</INACTIVE>
            <HOLD>0</HOLD>
            <CRCARDID />
            <CRCRDNUM />
            <CCRDXPDT>1900-01-01T00:00:00</CCRDXPDT>
            <KPDSTHST>1</KPDSTHST>
            <KPCALHST>1</KPCALHST>
            <KPERHIST>1</KPERHIST>
            <KPTRXHST>1</KPTRXHST>
            <CREATDDT>1970-01-01T00:00:00</CREATDDT>
            <MODIFDT>2004-01-30T00:00:00</MODIFDT>
            <Revalue_Customer>1</Revalue_Customer>
            <Post_Results_To>0</Post_Results_To>
            <FINCHID />
            <GOVCRPID />
            <GOVINDID />
            <DISGRPER>0</DISGRPER>
            <DUEGRPER>0</DUEGRPER>
            <DOCFMTID />
            <Send_Email_Statements>0</Send_Email_Statements>
            <GPSFOINTEGRATIONID />
            <INTEGRATIONSOURCE>0</INTEGRATIONSOURCE>
            <INTEGRATIONID />
        </Customer>
    </eConnect>
</root>