EDI templates are the .NET classes for each message. The reader loads them by assembly name. This guide builds a console that reads an X12 file, then shows the three ways to supply those classes.
Sign up free for Community Or start from the X12 examples
Which templates you get
| Plan | What you add to the project | Use it for |
|---|---|---|
| Community | NuGet packages such as EdiFabric.Templates.X12, or a compiled DLL from EdiNation
|
Evaluation. The NuGet models are a Community limitation and cover the versions in the examples. |
| Developer and Enterprise | Plain C# files for every template. Add the transactions you need to a class library. | Production. You ship only those messages, and you can edit a template per partner. |
The same classes parse and validate. If a transaction is missing, ask for it. Background on the model is in EDI templates.
Create the console
-
Create a console and add EdiFabric 11. Package targets are .NET 8, .NET 9, .NET 10, and .NET Framework 4.8.
dotnet new console -n ReadX12 cd ReadX12 dotnet add package EdiFabricIn Visual Studio the same install is
Install-Package EdiFabric. Details are in Install EdiFabric. - Sign up for Community and copy the serial from Your Account. How the three license calls differ is in Serial key authentication.
- Replace
Program.cswith the read below. Then follow one of the template sections and set the assembly name.
using EdiFabric.Core.Model.Edi;
using EdiFabric.Framework.Readers;
using EdiFabric.Templates.X12004010;
License.SetSerial("your-community-serial-key");
var x12File = File.OpenRead(@"C:\edi\PurchaseOrders.txt");
List<IEdiItem> ediItems;
using (var reader = new X12Reader(x12File, "EdiFabric.Templates.X12",
new X12ReaderSettings { ContinueOnError = true }))
{
ediItems = reader.ReadToEnd().ToList();
}
var purchaseOrders = ediItems.OfType<TS850>();X12Reader takes the stream and the assembly name that contains the template classes. ContinueOnError keeps reading after a bad transaction. HIPAA uses the same reader with assembly EdiFabric.Templates.Hipaa. On Developer, call License.EnsureToken instead of License.SetSerial.
Community: install the NuGet templates
This is the fastest path, and the one the X12 examples use.
dotnet add package EdiFabric.Templates.X12Pass "EdiFabric.Templates.X12" as the assembly name. After install, the project references look like this:
| Standard | Package and assembly name |
|---|---|
| X12 | EdiFabric.Templates.X12 |
| HIPAA | EdiFabric.Templates.Hipaa |
| EDIFACT and EANCOM | EdiFabric.Templates.Edifact |
| HL7 | EdiFabric.Templates.Hl7 |
| NCPDP Telecommunication and SCRIPT | EdiFabric.Templates.Ncpdp |
| IATA PADIS | EdiFabric.Templates.Padis |
| VDA | EdiFabric.Templates.Vda |
| EDIGAS | EdiFabric.Templates.Edigas |
Class names are TS plus the transaction id, in a version namespace. An X12 4010 invoice is EdiFabric.Templates.X12004010.TS810. An EDIFACT D96A invoice is EdiFabric.Templates.EdifactD96A.TSINVOIC.
Paid plans: add the C# files
Paid plans deliver every template as C# source, under EdiFabric.Sdk\EDI Templates in the SDK download. Put one version (or one partner) in one class library, and reference that library from the console.
- Add a Class Library to the solution. Delete
Class1.cs. -
Install EdiFabric into that library.
dotnet add package EdiFabric - On .NET Framework only, reference
System.Runtime.SerializationandSystem.Xml.Serialization. -
Add the message file you need (this example is X12 4010 transaction 850) and every file in that version's Common folder. Common is the five files ending in
_Codes.cs,_ComplexElementInterfaces.cs,_ComplexElements.cs,_SegmentInterfaces.cs, and_Segments.cs. -
Reference the class library from the console.
-
Pass the class library's assembly name to the reader. If the project is
ClassLibrary1, that argument is"ClassLibrary1". It is the assembly name, not the namespace ofTS850.using (var reader = new X12Reader(x12File, "ClassLibrary1", new X12ReaderSettings { ContinueOnError = true }))
At runtime you can load several template assemblies, or a C# type directly. The matching-templates section of Parse EDI files shows both.
Community: download a compiled template from EdiNation
Use this when you need a version that is not in the NuGet evaluation packages. The download is a single DLL for that version, and it targets .NET 6 and later. Browse versions without an account in the EdiNation spec library.
-
Open the spec library and select the standard and version, for example X12 005010.
-
Download the templates. The file name follows the version, for example EdiNation.X12.ASC.005010.dll.
-
Reference that DLL from the console.
-
Pass the DLL name without
.dllas the assembly name.using (var reader = new X12Reader(x12File, "EdiNation.X12.ASC.005010", new X12ReaderSettings { ContinueOnError = true }))
These DLLs bundle every transaction in the version, so they are large. For a production app, use the C# files and include only the messages you translate.
Which path to use
- Trying a sample or a known version. Install the NuGet template package.
- A version the NuGet package does not include. Download the compiled DLL from EdiNation while you are on Community.
- Shipping. Add the paid C# files to a class library. You keep the transactions you need, you can change a template for a partner, and you can pack that library as a DLL or a local NuGet package.
The NuGet and EdiNation assemblies still load on a paid plan. They stay limited to the versions they were built from. The full list of example versions is in the C# examples.
Comments
0 comments
Please sign in to leave a comment.