Monday 29 December 2014

Call Web service from Biztalk Orchestration

For demonstration I will be calling free currency converter service

  http://www.webservicex.net/CurrencyConvertor.asmx?WSDL


Right click on your biz talk solution and add generated item.









After adding the generated item we will get solution structure as below



open the orchestration file and drag shapes as per below screen shot


choose existing port type for request response(soap)



sample request

response










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);






Sunday 28 December 2014

Dynamic mapping

Dynamic Mapping demo

SCHEMA'S




















Mapping





Transformation logic inside expression shape:


MapType = System.Type.GetType("DynamicMappingDemo.CanonicalToCustomerA,DynamicMappingDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1e189bdf5b6a5b37");

construct customerA
{
transform (customerA) = MapType(generic);
}

//log meesgae
xmlDoc=customerA;
System.Diagnostics.EventLog.WriteEntry("DynamicTransformDemo","customerA:"+xmlDoc.OuterXml);



MapType = System.Type.GetType("DynamicMappingDemo.CanonicalToCustomerB,DynamicMappingDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1e189bdf5b6a5b37");

construct CustomerB
{
transform (CustomerB) = MapType(generic);
}

//log meesgae
xmlDoc=CustomerB;
System.Diagnostics.EventLog.WriteEntry("DynamicTransformDemo","customerB:"+xmlDoc.OuterXml);


solution files



sample inputs:

<ns0:Canonical xmlns:ns0="http://DynamicMappingDemo.Canonical">
  <Customer>
    <id>A</id>
    <name>name_A</name>
  </Customer>
</ns0:Canonical>


<ns0:Canonical xmlns:ns0="http://DynamicMappingDemo.Canonical">
  <Customer>
    <id>B</id>
    <name>name_B</name>
  </Customer>
</ns0:Canonical>




sample out put that will be logged inside event viewer

customerA:<ns0:CustomerA xmlns:ns0="http://DynamicMappingDemo.CustomerA"><ID>A</ID><NAME>name_A</NAME></ns0:CustomerA>


customerB:<ns0:CustomerB xmlns:ns0="http://DynamicMappingDemo.CustomerB"><ID>B</ID><NAME>name_B</NAME></ns0:CustomerB>




MessageAggregation

MessageAggregation using sendpipeline


order schema structure
shippingInfoStructure



envelope schema


Set envelope property to yes (goto schema property set envelope property to yes)

set body xpath to record 

/*[local-name()='Envelope' and namespace-uri()='http://MessageAgrregator.OrderEnvelope']/*[local-name()='Record' and namespace-uri()='']


set document schema and envelope property as shown below




aggregation logic

Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteSendPipeline(typeof(MessageAgrregator.MessageAggregatorSend),MessagesToAggregate,AggregatedMessage);

solution structure




sample input 


sample output in event viewer







Friday 26 December 2014

table looping functoid

Consider the following schemas:
Source schema:

Destination schema:

One’s first attempt at a map to transform the source to destination might look something like this:

We'll use the following input file to test the map.

The output isn't quite what we were hoping for. Rather than creating two borrower nodes, the two first names, last names, and SSNs are within a single borrower node.

The Table Looping functoid is the key to what we're trying to achieve. Below is the map that uses the Table Looping and Table Extractor functoids to create the desired output.

The Borrower fields are used as inputs into the Table Looping functoid as well as some definitions about how many rows and columns there will be. One tip I gleaned from Dan Shultz is to label the input links, as they'll be infinitely more readable within the Table Looping inputs window.

The first two arguments are akin to defining the number of rows and the number of columns for the table, and the rest of the arguments define the values that will be used within the table. By opening up the Table Looping Grid, we're able to view which fields will go into certain columns/rows:

The Table Extractor functoids are used to define which columns from the table map to use as inputs. Each Table Extractor functoid corresponds to a column within the Table Looping Grid.

And finally the output from Table Looping functoid to the Borrower node dictates that a Borrower node be created for each row within the Table Looping Grid. With that said, here’s the output from testing the second map:


Looping Functoid

Looping Functoid


The Looping functoid combines multiple records or fields in the source schema into a single record in the destination schema.
The following figure shows a Looping functoid used in a map to combine addresses collected from two different surveys into a single master address list.
Looping Functoid Map
The FoodSurvey and FlowerSurvey looping records of the source schema are mapped to the looping Address record of the destination schema. If an input instance message has three FoodSurvey records and twoFlowerSurvey records, the Looping functoid combines these to create five Address records in the output instance message.
The following code is a sample input instance message.
<ns0:Surveys xmlns:ns0="http://LoopingFunctoid.Surveys">
    <FoodSurvey Name="Karin Zimprich" Address="345 N 63rd St" City="Boston" State="MA" PostalCode="07485" />
    <FoodSurvey Name="Wendy Wheeler" Address="7890 Broadway" City="Columbus" State="OH" PostalCode="46290" />
    <FoodSurvey Name="Florian Voss" Address="1234 Main St" City="Denver" State="CO" PostalCode="97402" />
    <FlowerSurvey Name="Kelly Focht" Address="456 1st Ave" City="Miami" State="FL" PostalCode="81406" />
    <FlowerSurvey Name="Jim Kim" Address="567 2nd Ave" City="Seattle" State="WA" PostalCode="98103" />
</ns0:Surveys>
This input instance message produces the following output instance message when processed by the map in the preceding figure.
<ns0:MasterAddresses xmlns:ns0="http://LoopingFunctoid.MasterAddresses">
    <Address Name="Karin Zimprich" Street="345 N 63rd St" City="Boston" State="MA" PostalCode="07458"/>
    <Address Name="Wendy Wheeler" Street="7890 Broadway" City="Columbus" State="OH" PostalCode="46290"/>
    <Address Name="Florian Voss" Street="1234 Main St" City="Denver" State="CO" PostalCode="97402"/>
    <Address Name="Kelly Focht" Street="456 1st Ave" City="Miami" State="FL" PostalCode="81406"/>
    <Address Name="Jim Kim" Street="567 2nd Ave" City="Seattle" State="WA" PostalCode="98103"/>
</ns0:MasterAddresses>