This article is Part 2 of a guide on working with BizTalk EDI’s Preserve Interchange feature.  Part 1 can be found at:

The source code for the sample solution is available in the Code Gallery at:

This article presents some advanced concepts and requires familiarity with BizTalk EDI processing in general. If you are new, please complete all the EDI Tutorials at:
Finally, debatching is done with the Loopback Adapter, a free download from TwoConnect:

Now, it time to work with Interchange containing multiple transaction types or GS…GE loops.

Schemas for Multiple Transaction Type

Processing multiple transaction interchanges uses almost the schemas as a single transaction interchange and the process to generate initial schemas is identical.  This process is described in the section Schema for Single Transaction Type in Part 1:

For this sample, the Schema names represent the EDI Structure they define.

Reference Schema

EnvelopeElements.xsd defines the elements of the envelope elements. The Generated Schema will also include definitions for ST and SE, but those can be ignored.  To reduce the number of entries on the Schemas list in BizTalk Administrator, an element named Root has been added only to be set as the Root Reference.

Message Schemas

EnvelopeSegments.xsd defines the 4 envelope segments, ISA, GS, GE and IEA.  During the debatching process, ISA and IEA will published as individual messages.

InterchangeXml_Debatch.xsd defines the root of a Preserve Interchange Message.  Because this Schema is used only for debatching, definitions below the root are not necessary. Items to note on this Schema:
  • The Envelope property of the Schema is set to Yes.
  • The Body XPath property of the X12InterchagneXml element is set to itself.
  • Unlike the Single method, InterchangeXml_Debatch.xsd does not Include any other schemas.
FunctionalGroupXml.xsd defines Functional Group, GS...GE, sections of the Preserve Interchange Xml. The element FunctionalGroup is a child of X12InterchangeXml and all instances of FunctionalGroup will be debatched into separate message along with ISA and IEA.

FnctionalGroup contains the DocType Attribute. The value of DocType is set to the BizTalk MessageType for the Transaction Set it contains, http://PreserveInterchangeSample# X12_00401_850. In this example, DocType is Promoted to the FunctionalGroupType Context Property so the message can be routed to an appropriate service, Orchestration or Send Port. Items to note on this Schema:
  • FunctionalGroupXml.xsd is not an Envelope Schema.
  • Under the FunctionalGroup element, the TransactionSet element loops when multiple ST…SE’s are present.  Each TransactionSet contains one ST…SE.
FunctionalGroupXml_Debatch.xml is identical to FunctionalGroupXml.xsd except that it is an Envelope Schema.

This schema is used where the individual Transaction Sets, ST��SE, can be processed individually.  Items to note in this Schema:
  • The Envelope property of the Schema is set to Yes.
  • The Body XPath property of the FunctionalGroup element is set to TransactionSet.
  • The debatched output is the same result as not using Preserve Interchange on the incoming EDI.

Other Artifacts

PreserveInterchangeDebatchingProperties.xsd defines Context Properties that are used when processing the EDI messages.  The most important is FunctionalGroupType which is Promoted in both of the FuinctionalGroupXml Schemas. This Property is used to route the Functional Groups by message type to their processing service.

ConsumeExtraMessages.odx provides a destination for the ISA and IEA message debatched from the X12InterchangeXml Message. This to prevent “no subscriber” errors when processing the interchange messages.

Pipelines Project

The sample Solution contains the Inbound_EDI_Multiple_Pipelines project which defines the two custom Pipelines use to process the messages:

  • DebatchInterchangeXml.btp
  • DebatchFunctionalGroup.btp
DebatchInterchangeXml.btp has the following Schemas defined:
  • Envelope: Inbound_EDI_Multiple.InterchangeXml_Debatch
  • Document: Inbound_EDI_Multiple.EnvelopeElements+ISA
  • Document: Inbound_EDI_Multiple.FunctionalGroupXml
  • Document: Inbound_EDI_Multiple.EnvelopeElements+IEA
DebatchFunctionalGroupXml.btp has the following Schemas defined:
  • Envelope: Inbound_EDI_Multiple. FunctionalGroupXml_Debatch
These pipelines are defined in a separate project to accommodate some specific behavior of the XmlDisassembler when resolving Schemas that are deployed in the same Assembly. By defining the Pipelines in a separate Assembly, the XmlDisassembler will consider only the Schemas set in the Pipeline Designer.

In Preserve Interchange scenarios, setting the Document Specs explicitly on the XmlDisassembler is a practical requirement because there is no build-in way to modify the namespace of the Interchange Xml Messages.

Sample Scenario

The scenario presented in the Sample Solution is one where the two Transaction Types are transmitted in the same Interchange, ISA…IEA, but should be handled differently. The 850 messages should be treated as a single batch while the 864 messages can be processed individually.

The message flow is as follows:
  • EDI Received by PreserveInterchangeSample Receive Location
    • X12InterchangeXml published to MessageBox
  • X12InterchangeXml routed to DebatchInterchanges Loopback Send Port
    • FunctionalGroup @DocType = http://PreserveInterchangeSample#X12_00401_850 published to Message Box
    • FunctionalGroup @DocType = http://PreserveInterchangeSample#X12_00401_864 published to Message Box
  • 850 FunctionalGroup Xml routed by @DocType, DebatchInterchange.FunctionalGroupType, to the X12_850_Send FILE Send Port.
    • Entire FunctionalGroup Xml is written to the file system.
  • 864 FunctionalGroup Xml routed by @DocType, DebatchInterchange.FunctionalGroupType, to the DebatchFunctionalGroups Send Port.
    • FunctionalGroup Xml is again debatched into individual X12_00401_864 Messages.
    • X12_00401_864’s are published to the MessageBox.
  • 864 Messages are routed by BTS.MessageType to the X12_856_Send FILE Send Port.
    • Individual 864 Message are written to the file system. 

Deploying and Running the Sample Solution

  • Download the code from the Code Gallery at 
  • Endure the Loopback Adapter is installed and registered as Loopback.
  • Create the following directories:
    • C:\Data\BizTalkFolders\PreserveInterchangeSample\IN
    • C:\Data\BizTalkFolders\PreserveInterchangeSample\OUT
  • Build and Deploy from Visual Studio.
  • Import the Partners.xml binding file from the PreserveInterchangeSample Application.
  • Import the PreserveInterchangeSample.BindingInfo.xml into the same Application.
  • Copy the Sample850+856.edi file to the IN folder.
  • Check the OUT folder 3 files should be created: 
    • 850FunctionalGroup_{GUID}.xml
    • 864TransactionSets_{GUID1}.xml
    • 864TransactionSets_{GUID2}.xml

When the Loopback Adapters’s Preserve Properties configuration property is set to True, the Adapter will echo back all properties set on the request message.  Because of this, FILE.ReceivedFileName will be preserved on all EDI Xml messages generated through this sample.


Preserve Interchange is an important option when processing EDI with BizTalk Server Apps.

Using the techniques described here, the Inbound batch processing option in the Agreement is no longer an all-or-nothing choice.  We can process transactions batched or individually depending on the business requirement.

Additionally, sequential processing of individual transaction types is facilitated because we can now rely on a single BizTalk Interchange (debatched from the FunctionalGroup) containing the single message type.

See Also

Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.