Monday, November 12, 2012

BizTalk 2010 - Create a dynamic flat file disassembler to set the document schema

In this scenario, there are quite a few different flat files in different flat file schema types, they all need to map into a common format schema to be processed in BizTalk.

It is will be too much to create pipeline for each trading party, so I wrote a custom flat file disassember which inherit from the Microsoft one to set the document schema in the disassemble stage.

There is an existing msdn example to show how to create a custom disassember which inheritted from the Flat file disassembler, Extending the Flat File Disassembler Pipeline Component.

In my scenario, I only need to have some custom code in the Disassemble() method.

1. Understand the received file name,
  IBaseMessageContext context = pInMsg.Context;

  object obj = context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties");
In this blog, you can find all the common used properties as reference.

2. Set the DocumentSpecName of the pipeline

DocumentSpecName is a type of SchemaWithNone, which need to add reference to Microsoft.BizTalk.Component.Utilities from GAC.

this property can be created by this.DocumentSpecName = new SchemaWithName("schematype, assemblyname, ..."); 

3. Then just call base.Disasseble(pContext, pInMsg)
4. To inherit from Flat file disassember (FFDasmComp class), need to add reference to Microsoft.BizTalk.Pipeline.Components from GAC. For the Pipeline components interface such as IBaseComponent, IDisassemblerComponent,need to add reference to Microsoft.BizTalk.Pipeline 

When add this custom component into the pipeline, the Flat File Disassembler needs the Document schema to be set up. Although you can override the IComponent.Validate() method to pass the validation, however, it will cause error "value can not be null" in the pipeline processing.

Also the flat file disassembler needs to set the "Recoverable Interchange processing" property to true, or else, there is a "datareader disposed" error sometimes.  

1 comment:

Unknown said...

Can you please give me the code for above scenario ?