Monday, 29 December 2014

Merge multiple biztalk canonical message of same type into single message

Merge multiple canonical message inside orchestration of same type into single message

Create a .net helper class as below

using System.Collections;
   [Serializable]
    public class BiztalkMessageHelper
    {  

        public XmlDocument UpdateXML(ArrayList msgs)
        {
            DataSet ds1 = new DataSet();
            DataSet ds2 = new DataSet();          
            XmlDocument mergedMessage = new XmlDocument();      
            ds1.ReadXml(new XmlNodeReader((XmlDocument)msgs[0]));

            for (int i = 1; i < msgs.ToArray().Length;i++ )
            {
                ds2.ReadXml(new XmlNodeReader((XmlDocument)msgs[i]));
                ds1.Merge(ds2);
                //ds3 = ds1;
            }
            mergedMessage.LoadXml(ds1.GetXml());
            return mergedMessage;
        }
 
    }
variables need to be added

  •  System.Collections.ArrayList let's say variable name is  arrayList
  •  "class written above" lets say variable name is biztalkMessageHelper
  •  XmlDocument lets say variable is xdoc

suppose we want to merge three messages of the same type: msg1,msg2,msg3
then we can  write the below code inside expression shape to merger all three message

arrayList=new System.Collections.ArrayList(3);
arrayList.Add(msg1);
arrayList.Add(msg2);
arrayList.Add(msg3);
xdoc=biztalkMessageHelper.UpdateXML(arrayList);






No comments:

Post a Comment