I get asked frequently 'how do I get started', and I usually say 'read the manual', but I'll give this a shot.
Here's a short walk through of how to get started using eConnect
First of all, understand that there are two ways to code eConnect. You can just use what I call the 'direct' method, or you can 'serialize'. I'm not going to get into serialization here, because it's a lot more complicated, but it involves instantiating eConnect objects, then populating them, then sending the object itself to eConnect. The advantage to using serialization is that eConnect does some checking and validation for you along the way and will solve some issues earlier. It will also prepopulate a lot of default values.
Lately I've been using the 'direct' method, because it's simpler and I can code it quicker. So, here goes.
Install eConnect according to the install guide. You'll only need the 'incoming service', I don't have a lot of use for the 'outgoing service' (but I'd be happy to post contrary opinions). Also, download the help file, I use this all day long and I reference it below.
Create a project for eConnect. For this example, we're going to discuss a standard windows app, but in practice I usually use a Windows Service app or a Web Service.
Bring the eConnect, Serialization, and MiscRoutines dlls into your app and set references to them. These are installed on your PC in the C:\Program Files\Common Files\microsoft shared\eConnect 10\Objects\Dot Net folder.
Add this code to your app
Imports System
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO
Imports Microsoft.GreatPlains.eConnect
Imports Microsoft.GreatPlains.eConnect.Serialization
Imports Microsoft.GreatPlains.eConnect.MiscRoutines
'==========================================================================
'this code will accept any econnect doc
'==========================================================================
Public Shared Sub main(ByVal xDoc As XmlDocument, ByVal db As String)
Dim strServer As String = System.Configuration.ConfigurationManager.AppSettings("server")
Dim strConnect As String = "data source=" & strServer & "; initial catalog=" & db & "; integrated security=SSPI; persist security info=False; packet size=4096"
Dim eConnResult As Boolean
'Instantiate an eConnectMethods object
Dim eConnObject As New eConnectMethods
Try
'If the update returned TRUE, it was successfully completed
eConnResult = eConnObject.eConnect_EntryPoint(strConnect, EnumTypes.ConnectionStringType.SqlClient, xDoc.OuterXml, EnumTypes.SchemaValidationType.None)
Catch ex As eConnectException
Throw New Exception(ex.Message)
Catch ex As System.Data.SqlClient.SqlException
Dim myError As System.Data.SqlClient.SqlError
Dim strMsg As String = ""
For Each myError In ex.Errors
strMsg += myError.Message + vbCrLf
Next
Throw New Exception(strMsg)
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
I'm not going to explain most of the code above, that's out of the scope of this article. However, note that we pass in an XML document. That document is an XML eConnect doc. I have several examples here (scroll to the bottom), and the help file has a lot, also.
I know that the error handling looks kind of 'over the top', but trust me, you need it.
If anyone has a specific question about the code, send it and I'll document it here.
<a xmlns:xsi="<a href=" href="http://www.w3.org/2001/XMLSchema-instance%22%3Ehttp://www.w3.org/2001/XMLSchema-instance%3C/a">http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a</a>" xmlns:xsd="<a href="<a href="http://www.w3.org/2001/XMLSchema%22%3Ehttp://www.w3.org/2001/XMLSchema%3C/a">http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a</a>">
<RMCustomerMasterType>
<taUpdateCreateCustomerRcd>
<CUSTNMBR>MYCUSTNUMBER</CUSTNMBR><!-- (REQUIRED) string(15) Customer number-->
<CUSTNAME>MYCUSTNAME</CUSTNAME>
</taUpdateCreateCustomerRcd>
</RMCustomerMasterType>
</eConnect>
Load the doc above into an XML document, and submit it to the 'main' sub. You'll have errors, I always do. Search this forum for the errors, you should find all of them.
The above is 1.0 documentation. Please send feedback on how I can improve it.