Scenario: Create plugin to read/publish edi transactions
Solution:
Per ediFabric documentaion
EdiFabric is Lightning-fast and easy-to-use developer SDK and API to parse, generate, validate, split, acknowledge, represent, view, and document EDI files.
Below are the steps to convert edi document to XML. This is for X12 format of edi.
- Register & download the EdiFabric package. It had DLL targeting different .net versions. Add appropriate to the project.
- Include the EDI templates in the project, which come with the package. These are based on edi format/ version. ex X12/002040. These have POCO classes for each edi transaction, e.g. EDI 832 [Catalog]/ EDI 846[Inventory] etc.
- Use EdiFabric.X12Reader to read the edi files. They could be serialized using XMLSerializer or DataContractSerilizer per above classes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace MyCoreSolution
{
public class EdiPlugin
{
public void ConvertEdidocumentoXML()
{
EdiFabric.SerialKey.Set();
var ediData = "";
//var ediData = File.OpenRead(@"");
var dataStream = new MemoryStream(Encoding.UTF8.GetBytes(ediData));
var ediItems = new List<IEdiItem>();
using (var reader = new X12Reader(dataStream, "namespace",
new X12ReaderSettings { ContinueOnError = false }))
{
ediItems = reader.ReadToEnd().ToList();
}
var transactions = ediItems.OfType<TS832>();
foreach (var transaction in transactions)
{
var xml = transaction.Serialize();
}
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace MyCoreSolution { public class EdiPlugin { public void ConvertEdidocumentoXML() { EdiFabric.SerialKey.Set(); var ediData = ""; //var ediData = File.OpenRead(@""); var dataStream = new MemoryStream(Encoding.UTF8.GetBytes(ediData)); var ediItems = new List<IEdiItem>(); using (var reader = new X12Reader(dataStream, "namespace", new X12ReaderSettings { ContinueOnError = false })) { ediItems = reader.ReadToEnd().ToList(); } var transactions = ediItems.OfType<TS832>(); foreach (var transaction in transactions) { var xml = transaction.Serialize(); } } } } |
No comments:
Post a Comment