Econnect is much faster if you are writing a module that will talk directly to the server where econnect is installed. Use web services for information passing from outside the server. Web services sits on top of econnect so bypassing web services eliminates an additional layer of processing for the data. Here is an example of the econnect integration for a sop transaction from the samples;
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Globalization;
using Microsoft.Dynamics.GP.eConnect;
using Microsoft.Dynamics.GP.eConnect.Serialization;
namespace eConnectSalesOrder_CSharp_ConsoleApplication
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class test
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using (eConnectMethods eConCall = new eConnectMethods())
{
try
{
// Create the eConnect document and store it in a file
SerializeSalesOrderObject("SalesOrder.xml");
// Load the eConnect XML document from the file into
// and XML document object
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("SalesOrder.xml");
// Create an XML string from the document object
string salesOrderDocument = xmldoc.OuterXml;
// Create a connection string
// Integrated Security is required. Integrated security=SSPI
// Update the data source and initial catalog to use the names of
// data server and company database
string sConnectionString = "data source=localhost;initial catalog=TWO;integrated security=SSPI;persist security info=False;packet size=4096";
// Use the CreateTransactionEntity method to create the sales document in Microsoft Dynamics GP
// The method returns a string that contains the doc ID number of the new sales document
string salesOrder = eConCall.CreateTransactionEntity(sConnectionString, salesOrderDocument);
}
// The eConnectException class will catch any business logic related errors from eConnect_EntryPoint.
catch (eConnectException exp)
{
Console.Write(exp.ToString());
}
// Catch any system error that might occurr. Display the error to the user
catch (Exception ex)
{
Console.Write(ex.ToString());
}
finally
{
// Use the Dipose method to release resources associated with the
// eConnectMethods objects
eConCall.Dispose();
}
}
}
private static void SerializeSalesOrderObject(string filename)
{
// Create a datetime format object
DateTimeFormatInfo dateFormat = new CultureInfo("en-US").DateTimeFormat;
try
{
// Create an array that can hold two taSopLineIvcInsert_ItemsTaSopLineIvcInsert objects
taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] LineItems = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[2];
// Create a taSopLineIvcInsert_ItemsTaSopLineIvcInsert object and populate its fields
taSopLineIvcInsert_ItemsTaSopLineIvcInsert salesLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
salesLine.ADDRESS1 = "2345 Main St.";
salesLine.CUSTNMBR = "CONTOSOL0001";
salesLine.CITY = "Aurora";
salesLine.SOPTYPE = 3;
salesLine.DOCID = "STDINV";
salesLine.QUANTITY = 2;
salesLine.ITEMNMBR = "ACCS-CRD-12WH";
salesLine.ITEMDESC = "Phone Cord - 12' White";
salesLine.UNITPRCE = 10.95m;
salesLine.XTNDPRCE = 21.9m;
salesLine.LOCNCODE = "WAREHOUSE";
salesLine.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy", dateFormat);
// Add the SOP line item object to the array
LineItems[0] = salesLine;
// Create a second taSopLineIvcInsert_ItemsTaSopLineIvcInsert object and populate its fields
taSopLineIvcInsert_ItemsTaSopLineIvcInsert salesLine2 = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
salesLine2.ADDRESS1 = "2345 Main St.";
salesLine2.CUSTNMBR = "CONTOSOL0001";
salesLine2.CITY = "Aurora";
salesLine2.SOPTYPE = 3;
salesLine2.DOCID = "STDINV";
salesLine2.QUANTITY = 2;
salesLine2.ITEMNMBR = "ACCS-CRD-25BK";
salesLine2.ITEMDESC = "Phone Cord - 25' Black";
salesLine2.UNITPRCE = 15.95m;
salesLine2.XTNDPRCE = 31.9m;
salesLine2.LOCNCODE = "WAREHOUSE";
salesLine2.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy", dateFormat);
// Add the SOP line item object to the array
LineItems[1] = salesLine2;
// Create a taSopHdrIvcInsert object and populate its fields
taSopHdrIvcInsert salesHdr = new taSopHdrIvcInsert();
salesHdr.SOPTYPE = 3;
salesHdr.DOCID = "STDINV";
salesHdr.BACHNUMB = "eConnect";
salesHdr.TAXSCHID = "USASTCITY-6*";
salesHdr.FRTSCHID = "USASTCITY-6*";
salesHdr.MSCSCHID = "USASTCITY-6*";
salesHdr.LOCNCODE = "WAREHOUSE";
salesHdr.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy", dateFormat);
salesHdr.CUSTNMBR = "CONTOSOL0001";
salesHdr.CUSTNAME = "Contoso, Ltd.";
salesHdr.ShipToName = "WAREHOUSE";
salesHdr.ADDRESS1 = "2345 Main St.";
salesHdr.CNTCPRSN = "Joe Healy";
salesHdr.FAXNUMBR = "13125550150";
salesHdr.CITY = "Aurora";
salesHdr.STATE = "IL";
salesHdr.ZIPCODE = "65700";
salesHdr.COUNTRY = "USA";
salesHdr.SUBTOTAL = 53.8m;
salesHdr.DOCAMNT = 53.8m;
salesHdr.USINGHEADERLEVELTAXES = 0;
salesHdr.PYMTRMID = "Net 30";
// Create a eConnect SOPTransactionType schema object
SOPTransactionType salesOrder = new SOPTransactionType();
// Populate the schema object with the SOP header and SOP line item objects
salesOrder.taSopLineIvcInsert_Items = LineItems;
salesOrder.taSopHdrIvcInsert = salesHdr;
// Create an array that holds SOPTransactionType objects
// Populate the array with the SOPTransactionType schema object
SOPTransactionType[] MySopTransactionType = { salesOrder };
// Create an eConnect XML document object and populate it
// with the SOPTransactionType schema object
eConnectType eConnect = new eConnectType();
eConnect.SOPTransactionType = MySopTransactionType;
// Create a file to hold the serialized eConnect XML document
FileStream fs = new FileStream(filename, FileMode.Create);
XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
// Serialize the eConnect document object to the file using the XmlTextWriter.
XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
serializer.Serialize(writer, eConnect);
writer.Close();
}
//If an eConnect exception occurs, notify the user
catch (eConnectException ex)
{
Console.Write(ex.ToString());
}
}
}
}
To insert a batch record first, you would follow the same steps except instead of SOPTransactionType, you would create a SMTransactionBatchType before you integrate the invoices/orders/quotes/etc.. The API fields all match the sql server physical names for econnect, and web services uses a more friendly version for the field names. You can use a site such as Tealbridge to reference the tables, fields and relationships in a quicker fashion than GP's built-in table reference guide. This is located here (http://www.tealbridge.com/free-resources/dynamics-gp-table-reference/2010?ref=sqlscript#)
HTH,
Josh P