Web Analytics
Skip to main content

Andosi - Blog

Where we discuss The Art of Great System Design

Microsoft Dynamics 10 eConnect C# 4.0 .NET Serialization In Memory

Bryan Prince

01 December 2010

*Note* - This code was written for Dynamics GP 10. If you are using Dynamics GP 2010 see this updated article.
I was recently tasked with creating an eConnect integration between Microsoft Dynamics GP 10 and a custom SharePoint 2010 Portal designed to replace the GP Item Maintenance process with workflow and departmental routing.

 

Most of the eConnect examples I see online serialize the eConnect object to a file before loading it into an XmlDocument. This can cause unnecessary permissions concerns, and worse, if your application runs under the context of IIS or SharePoint you may not have a file system available to you at all. This was the case in my scenario. A much better approach is to serialize the object in memory.

 
Below is an example of eConnect serialization in memory using Microsoft C# .NET 4.0.
 
Assuming you have already installed the eConnect SDK 10, reference the following assemblies:
 
Microsoft.Dynamics.GP.eConnect.dll
Microsoft.Dynamics.GP.eConnect.MiscRoutines.dll
Microsoft.Dynamics.GP.eConnect.Serialization.dll
System.EnterpriseServices.dll
 
And add the following using statements:
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Dynamics.GP.eConnect;
using Microsoft.Dynamics.GP.eConnect.Serialization;
Here is the code to serialize the eConnectType object in memory and load it into an XmlDocument which is then passed to the eConnect_EntryPoint method:
 
string connectionString = string.Empty; // Set up a valid connection string.

eConnectMethods econnectMethods = new eConnectMethods();
eConnectType eConnectType = new eConnectType();

// Instantiate and populate the specific eConnect types needed.
// Don't forget to add them to eConnectType once they are set up.

// We're done building the object model, now serialize it in memory.
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xmlSerializer = new XmlSerializer(eConnectType.GetType());
xmlSerializer.Serialize(memoryStream, eConnectType);
memoryStream.Position = 0;

// Create a new XmlDocument from the in memory serialized object model.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(memoryStream);
memoryStream.Close();

econnectMethods.eConnect_EntryPoint(connectionString, EnumTypes.ConnectionStringType.SqlClient, xmlDocument.OuterXml, EnumTypes.SchemaValidationType.None, string.Empty);
 
Hope it helps!
This blog has been relocated from http://mbsguru.blogspot.com/ with authorization.
 

More Blog Posts


Really???? Dynamics GP Report Writer is the Best Report Writer in the World?

Michael Johnson
Wow!  I never thought I'd have an opportunity to jump between Polino and Musgrave in a squabble but I just can't resist any longer.  Maybe they'll break out the sumo suits at Tech Conference this year and they can settle this debate once and for a...

Support Debugging Tool Build 14 released

Michael Johnson
The latest build of the Support Debugging Tool has been released by THE David Musgrave.  Check out the fixes, enhancements, and new features here http://blogs.msdn.com/b/developingfordynamicsgp/archive/2010/12/02/support-debugging-tool-build-14-re...