Calling eConnect.dll from BizTalk Server 2006
[Cross-post from old blog.]
eConnect is a great tool for integrating with Dynamics GP; however I am currently stuck on Great Plains 8.0 and there is not a BizTalk 2006 adapter for eConnect 8. So I've decided to call the assembly directly from my orchestration.
Since I anticipate calling this from multiple BizTalk applications, I have decided to deploy the eConnect-only components as a separate BizTalk application.
Schemas
Currently I have the need to push Purchase Order and Inventory Site data to GP. I have created three schemas:
- GP_eConnectProcess_XML.xsd: Contains the <eConnectProcessInfo> XML node;
- GP_IV_InventorySite_XML.xsd: Contains the <IVInventorySiteType> XML node, and below this we include the <eConnectProcessInfo> element from the previous schema (see example below);
- GP_IV_POPTransAction_XML.xsd: Just like the InventorySite schema, we have included the necessary elements we require (in this case taPoLine_Items and taPoHdr) and again we include the eConnectProcessInfo schema.
Assembly
Within my eConnectBTS assembly, I have two public static methods: eConnect_SendDoc which receives the XLANG message for eConnect; and eConnect_Send which receives the eConnect XML and calls the eConnect.dll.
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using Microsoft.GreatPlains.eConnect;
using Microsoft.XLANGs.BaseTypes;
namespace MyCompany.GP.eConnect
{
public class eConnectBTS
{
#region Class Constructor
private eConnectBTS() { }
#endregion Class Constructor
#region eConnect Methods
/// <summary>
/// Sends XLANG message to eConnect DLL.
/// </summary>
/// <param name="eConnectDoc">XLANG message containing eConnect XML.</param>
/// <param name="ConnectionString">Connection string to GP database.</param>
public static void eConnect_SendDoc(XLANGMessage eConnectDoc, string ConnectionString)
{
// Get XML document from XLANG message :
XmlDocument eConnectXML = (XmlDocument)eConnectDoc[0].RetrieveAs(typeof(XmlDocument));
// Send to eConnect :
eConnect_Send(eConnectXML, ConnectionString);
}
/// <summary>
/// Sends XML document to eConnect_EntryPoint dll method.
/// </summary>
/// <param name="eConnectDoc">eConnect-format XML document.</param>
/// <param name="ConnectionString">Connection string to GP database.</param>
public static void eConnect_Send(XmlDocument eConnectDoc, string ConnectionString)
{
// Check Connection String :
if (ConnectionString == null)
throw new ArgumentNullException("ConnectionString");
if (ConnectionString.Trim() == "")
throw new ArgumentException("Connection string cannot be empty.", "ConnectionString");
eConnectMethods ec = new eConnectMethods();
bool isOK = false;
try
{
// Push to eConnect :
isOK = ec.eConnect_EntryPoint(ConnectionString, EnumTypes.ConnectionStringType.SqlClient,
eConnectDoc.OuterXml, EnumTypes.SchemaValidationType.None, null);
}
catch (System.Data.SqlClient.SqlException ex)
{
// In the case of SQL exceptions, I'd like a little additional data :
string strProc = ex.Procedure.Trim();
string strMessage = ex.Message.Trim();
throw new Exception(String.Format("SqlException thrown. Proc: {0} / Message: {1}", strProc, strMessage), ex);
}
// If EntryPoint returns false :
if (!isOK)
{
throw new Exception("eConnect_EntryPoint returned false but no exception was thrown.");
}
}
#endregion eConnect Methods
}
}
Calling from Orchestration
My orchestration assembly has a reference to both of my assemblies mentioned above (MyCompany.GP.eConnect and MyCompany.GP.eConnect.Schemas), and messages based on the IVInventorySite and POPTransaction schemas.
To send an XLANG message to eConnect, I have to configure my connection string variable. In my configuration, a transaction could be destined for one of two GP servers and one of over 200 GP databases. Therefore I construct my connection string dynamically based on data within the incoming document, but you can handle this any number of other ways, including using the Business Rules Engine included with BizTalk Server 2006.
To demonstrate this I've assembled a fairly simple orchestration. First we receive a new purchase order, we map it to the eConnect schema for this transaction type, and finally we have an expression shape with the single command shown below.
Comments
- Anonymous
May 23, 2007
The comment has been removed - Anonymous
April 20, 2009
Download the eConnect SDK. If you do not have access to the SDK, try getting with your partner for the download. It should be available from PartnerSource. - Anonymous
May 11, 2009
Hi,I do not know what parameters which you had transfered for eConnectDoc (XLANGMessage) and(XMLDocument)variables. Please help me!!!.Thanks