BizTalk: Log HL7 Parsing Errors

HL7 Disassembler writes parsing errors in windows event log and there is no documented way to get those error through code to log in custom database or some other data store.

Here is what HL7 pipeline writes into event log:


we can get these error in code by writing a wrapper disassembler component on top of HL7 OOTB Disassembler

Omitting details about how to write a custom pipeline component, we just need to override Disassemble and GetNext methods

  public HL7DASM()
            HL7Dasm = new HL72fDasm();
      public new void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
            HL7Dasm.Disassemble(pContext, pInMsg);

If HL7 party is configured to return ACKs, GetNext() method will execute multiple times.

public new IBaseMessage GetNext(IPipelineContext pContext)
            IBaseMessage msg = HL7Dasm.GetNext(pContext);

            if (msg != null && !msg.BodyPart.Data.CanSeek)  //if parsing fails, stream is not seekable

                 FieldInfo ParserErrorField = HL7Dasm.GetType().GetField("mBodyErrors", BindingFlags.NonPublic | BindingFlags.Instance); 
var ParserError = (System.Collections.ArrayList)ParserErrorField.GetValue(HL7Dasm);
StringBuilder errorList = new StringBuilder();

                foreach (HL7Error error in ParserError)
    // now errorList string contains all parsing errors details in same format as in windows event log
            return msg;



4 Responses to “BizTalk: Log HL7 Parsing Errors”

  1. Dheer Says:

    This is really a nice post .. I am also trying to do that same but not able to get the things working .. can you please provide me the entire code of this component.

  2. dthomas Says:

    Where are you instantiating HL7Error object and can you share the entire custom pipeline component.

  3. Usman Shaheen Says:

    For HL7Error class, add reference to Microsoft.Solutions.BTAHL7.Pipelines in project

  4. dthomas Says:

    Thank You. Can you share the entire Custom pipeline component code? I was also trying to understand how you instantiated HL7Dasm object.
    I want to capture the error thrown out after validating the HL7 file and send the error to Esb Exception database. I feel your code snippet is the pointing me to the right direction.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: