Saturday, December 29, 2012

Sequential convoy using listen shape in biztalk example

What is Sequential Convoy in BizTalk ?

A sequential convoy enables multiple single messages to join together to achieve a required result. A sequential convoy is a set of related messages that have a predefined order. Although the messages do not have to be exactly the same, BizTalk Server must receive them in a sequential order.

Listen Shape in BizTalk Example -:

Listen shape in BizTalk is the most powerful shape available in Orchestration developer toolbox. It can be used in many design patterns for BizTalk Soluton. Listen shape listens for some event to take place in its every branch. Suppose there are 3 branches in Listen shape and an event on 2nd branch takes place then all other branches would get terminated.

Sequential Convoy using Listen Shape 

I am going to demonstrate a sequential convoy using listen shape.
Suppose we have a file for Purchase order (PO) and a second file for Customer detail for that particular PO. We have to concatenate these two files and send it further. 

Schema for 1st File i.e PO :

Since we are using Sequential convoy we need to define a correlation set and type. Therefore I have promoted the PONo field in both the schema.

Schema for 2nd File i.e Customer Details :

Destination Schema :

Orchestration goes like this :

In Orchestration I have used a Uniform Sequential convoy which means that the Orchestration can receive messages from same logical Orchestration port. There are two receive shapes in Orchestration where the 1st receive shape initializes the correlation set and is marked activating. The 2nd receive shape follows the correlation set. The only thing that we need to take care is that ordered delivery property of the receive port must to true.
First branch of Listen shape contain receive shape and transform shape. When Orchestration receives the PO file, the orchestration becomes dehydrate and waits for the 2nd file i.e customer file to arrive. If the file comes before the time specified in the delay shape then the first branch of listen shape executes otherwise second branch of expression shape executes.

Map :

Input Files :

PO file

<ns0:PO xmlns:ns0="http://Working_With_ListenShape.SourceSch">

Customer file :

<ns0:Customer xmlns:ns0="http://Working_With_ListenShape.SourceSch1">

Output : 

Case 1 : When 2nd file arrives before the time specified in delay shape.

Case 2 : When event on Delay branch happens then output in Debug View :

Saturday, December 22, 2012

Parallel shape in biztalk example

Parallel shape in BizTalk is most confusing shape in Orchestration toolbox. I am going to give an example of parallel shape for removing this confusion.

What does Parallel shape in BizTalk do ?

Parallel shape in BizTalk is NOT used for concurrent processing. The Parallel shape enables you to complete different stages of business process without having to wait for another part of the business process to complete. It does not provide a separate thread per branch.

Example :

I have created an orchestration with a parallel shape which have 3 branches containing 3 expression shape. 

1st Expression shape :

2nd Expression Shape :

3rd Expression Shape :

How parallel shape works :

When we drop a file at receive location Orchestration in instantiated and when control reaches the parallel shape, it starts it execution from left to right i.e. the 1st expression shape runs firstly and then rest of them. Even if we insert delay shape after 1st expression shape the 2nd expression shape does not get starts.So therefore parallel shape is not about concurrent execution.

Output in DebugView :


Sunday, November 25, 2012

Modifying vocabulary without increasing the version in BRE

There are times when a developer/analyst wants to modify the vocabulary of the BRE without changing the version of the current vocabulary. This can be done with the help of the BizTalkRuleEngineDb which is created when we install our BizTalk Server. 

I have created a vocabulary called AgeValidation as shown below :

When we create a vocabulary and publish it then a database entry occurs into the Vocabulary table of BizTalkRuleEngineDb database as shown below :

There are several fields in this table but there are 3 fields that are of our interest i.e. nStatus, nMajor, nMinor. When we creating the vocabulary and when it is saved the nStatus field value in DB changes to 0, and when we publish the vocabulary its status changes to 1.

How do we modify the published vocabulary ?

Simply update the nStatus of your vocabulary to 0 and now refresh your BRE. Now our vocabulary will be in saved status and we can easily modify the vocabulary and publish it later on.

All about nMajor and nMinor :

The nMajor and nMinor fields are nothing but indication of the version of your vocabulary.
I have now created 3 versions of same vocabulary :

Now the effect on the vocabulary table in SQL is like this :

This means that when we create a new version of the vocabulary nMinor of the vocabulary keep on increasing.

Tuesday, November 13, 2012

Splitting a Flat-file with multiple records to multiple files with single record.

In BizTalk we can split a flat-file with multiple records to multiple files with single record.
This can be done with Envelope schema or using the below method.

Scenario : 

Suppose we have a input flat-file with multiple records of Purchase Orders of various customers.
Output should be a different file with single Purchase order of the customer.

Solution :

Input File structure:


Note : There is an enter at the end of the file.

Source Schema :

Create a source schema with a parent record Root and its child record PurchaseOrder.
Set child delimiter for Root node to 0x0D 0x0A i.e. enter and child order to Postfix.

In the above pic highlighted is the properties that we need to set i.e Group Max occur =1 and Group Min occur =0.

PurchaseOrder record properties :

Set child delimiter for PurchaseOrder node to ',' i.e. comma and child order to Infix.

In the above pic highlighted is the properties that we need to set i.e Max occur =1 and Min occur =0.

Destination Schema :

Map :

Receive Pipeline :

Output Files :

There were 6 records in the input files, hence in there are 6 XML files in the output.

Port Creation\Configuration :

Receive Port & Receive Location- Create a receive port and a receive location after deploying the solution. Select receive pipeline created in the solution on receive location and poll for a specific location using *.txt mask.

Send Port - Create a send port with filter property set to receive port name and in outbound map select the map created in the solution.

How this works :

Setting the Max occur property =1 is responsible for debatching the flat file. When we set Max occur prperty = unbounded, it automatically receive multiple records of the file. In the same manner if we set Max occur =1 schema will only take a single record at a time, mapping will be done for this record and a separate file will be created for this record. Actually all this work is done by the receive pipeline. It will debatch the file while seeing the Max occur property =1 set on the schema.

Using Logical Existence functoid to remove empty node generation in BizTalk Mapper.

Generation of empty node in our XML is a common problem. We can halt the generation of empty nodes in BizTalk Mapper by the use of Logical Existence functiod.

Scenario :
                   Suppose we have to map the Customer's details. We have two records i.e. Customer (which contains header details) and Customer_Details (which contains details) in source schema. In destination schema we have three records i.e. Customer_Header, Customer_Details and ShippingAddress.

Now suppose that the source schema record Customer_Details is not mandatory so can be present or not, and it is mapped to Customer_Details and Address records of Destination Schema.
Now when the source schema record Customer_Details is not present then it creates the empty records.

Source Schema :

Destination Schema :

Input XML file without Customer_Details record :

<ns0:Customer_Data xmlns:ns0="http://Using_LogicalExistense.Customer_SourceSchema">

Map without Logical existence :

Output after Test Map using above XML file :

In the above result Cusomer_Details and ShippingAddress are generating empty.Mapping the Logical Existence functiod to these records that are generating empty solves our problem.

Map after using logical existence functiod :

Result After Test Map and using Logical Existence :

What Logical Existence does ?

The logical functiod is used to determine whether the RecordField Element, or Field Attribute node that is linked to it exists in a particular input instance message. If functiod evaluates to true then destination schema node is generated otherwise not.

Using XSL Choose in inline XSLT in BizTalk mapper

We can use <xsl;choose> in BizTalk mapper using inline XSLT.
Scenario : Suppose if a XML is coming to BizTalk server and we have to check that if a customer is 'Premium' or 'Normal' or anything then we can use <xsl:choose> to check these conditions.

Source Schema :

Destination Schema :


In BizTalk Mapper we can add a scripting functiod and add the inline XSLT to the functiod.

Inline XSLT :

  <xsl:for-each select ="Data">
      <xsl:variable name="var:v1" select="EmployeeType/text()" />
        <xsl:when test="$var:v1 = 'Premium'">
            <xsl:value-of select="Employee_Name/text()"/>
        <xsl:when test="$var:v1 = 'Normal'">
            <xsl:value-of select="EmployeeID/text()"/>
            <xsl:value-of select="Address/text()"/>

Input XML:

Case 1:

<?xml version="1.0"?>
-<ns0:Employee xmlns:ns0="http://XSLT_Test.Source">

Case 2:

<?xml version="1.0"?>
-<ns0:Employee xmlns:ns0="http://XSLT_Test.Source">

Case 3:

<?xml version="1.0"?>
-<ns0:Employee xmlns:ns0="http://XSLT_Test.Source">

Test Map Results :

We can Test the map using "Test Map" and following are the results :

Case 1 :

<EmployeeDetail xmlns:ns0="http://XSLT_Test.Destination">


Case 2 :

<EmployeeDetail xmlns:ns0="http://XSLT_Test.Destination">


Case 3 :
     <EmployeeDetail xmlns:ns0="http://XSLT_Test.Destination">


From above result we can see that how <xsl:choose> can be used to decide on the conditions.
When the input was a 'Premium' customer then the result was only 'Name' field.
    When the input was a 'Normal' customer then the result was only 'ID' field.
    When the input was a 'Invalid' customer then the result was only 'Address' field.

Using inline XSLT in BizTalk Map.

We can use inline XSLT in Biztalk maps for transformations. I'll be using inline XSLT and calling a simple C# class in the XSLT. For this we have to write XSLT in scripting functiod also write a class in inline c# of scripting functiod.

Below is the source schema used for map.

Destination Schema is :

Map goes like this :

XSLT goes like this :

<xsl:for-each select = "Root">
<Name><xsl:value-of select = "Name/text()" />
</Name><ID><xsl:value-of select ="ID/text()"/>
</ID><xsl:variable name="var:v1" select="userCSharp:concatAddress(string(Name/text()) , string(Address/text()))" />
<xsl:value-of select ="$var:v1" />
<xsl:variable name="var:v2" select = "userCSharp:AddID (string (ID/text() ),string(Roll_No/text()))"/>
<Roll_No><xsl:value-of select = "$var:v2"/>
</Roll_No><xsl:if test="not(string(ID/text())=0)">
<xsl:value-of select ="ID/text()"/>

C# script goes like this :

public string concatAddress(string Name, string Address){

return Name + Address;}
public int AddID(int ID,int RollNo){

return ( ID + RollNo); }

In XSLT code I have called both these methods. Just droppping the inline C# functiod on mapper surface will work fine,also we don't have to connect this sfunctiod to any node in destination schema.

Sunday, September 30, 2012

What is BizTalk Server ?

BizTalk is an Integration tool from Microsoft. Initially it was used for EAI (Enterprise Application Integration) but now a days it is used for BPM , Message Broker, EAI , B2B and many more.