DynDeveloper.com

DynDeveloper.com

Sign Up Now! Log In
hgkobayashi 3/12/2008 4:06:42 PM

Problem converting eConnect VB sample to C#

Hello.  First, I wanted to say great site!

I'm just getting started with eConnect and am trying to work through the examples in the eConnect Programmer's Guide and Reference.  Specifically, I am working on the eConnectOut Serialization Example.  I am able to get it working if I create a VB project, but cannot get it to work for C# (I only know C#).  I have been able to convert pretty much the entire code to C# except for the 'ReDim Preserve' statement.  Since there isn't an equivalent statement in C#, I have no idea how to go about converting it from VB.  I have googled it and worked through many suggestions on how to convert it without any luck.  It's probably something simple, but I cannot figure it out and was hoping someone here could shed a little insight.  Any help or information you could provide would be extremely helpful.  I will post the entire code below for your reference, but I will highlight the section I am having trouble with.  Thank you so much in advance!

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
Version: Unknown or N/A
Section: eConnect