Friday 13 February 2009

C# Generics works with BizTalk Server 2009 (Beta) :)

I have tried yesterday and it worked.  I am really one of the happiest persons to have C# Generics support in BizTalk.

Though Generics was introduced in Version 2.0 of C# and CLR, BizTalk till its version 2006 R2 doesn't support it. But now the story has changed. Yes, BizTalk Server 2009-Beta can support C# helper class with typed parameters i.e. Generics.

In the BizTalk Server version till 2006 R2, though we can't use the C# helper class which has Generics defined in it, we can utilise them indirectly by creating a wrapper class around them. By making this way, we can still abide the rules of BizTalk Server i.e. of not exposing the class with Generics in it directly. But now in BizTalk Server 2009 Beta, we don't have to search for any workaround for using Generics.

Lets see a real time example where we will use C# Generics with BizTalk. I have a database table called "Employee" which contains Employee details (obviously). And as part of the message processing in BizTalk I have to retrieve the Employee name for the given Employee ID. So I'll use a C# helper class to retrieve the EmployeeName for the EmployeeID which will be passed in as a input parameter to a method in it. I have to design the C# helper project in a object-oriented way something like

image

In the EmployeesDataProvider class, I have defined the Generics as..

public  List<Employee> employeeList = new List<Employee>();

to populate it with the result of "select * from Employee" then I'll add this to cache. So next time I'll populate the "employeeList" only if the cache is NULL. Thus avoids the database trips. And use Generics search functionality to get the result from the "employeeList" collection as..

Employee cusTemp = employeeList.Find(delegate(Employee _cus)
           {
               if (_cus.EmployeeID == strEmployeeID)
               {
                   return true;

               }
               return false;
           });

           if (cusTemp != null)
           {
               ret = cusTemp.EmployeeName.ToString();
           }

So the functionality of my helper class is:

Build the EmployeesList (typed class with Generics)from database if its not in the cache / other wise use the cached employee list and use the Generics's Find method to get the EmployeeName for the given EmployeeID.

Now in to BizTalk Server (till 2006 R2), inside the Orchestration's expression shape you may not be able to initiate the EmployeesDataProvider class. Reason being, this class has got the "Generics" type declaration. But now, the same works in BizTalk Sever 2009. Here you can see in BizTalk Server 2009-Beta, the class containing Generics recognised.

GenericsWorking

Download source code for "Generics in BizTalk Server 2009": http://cid-01845bf64da73117.skydrive.live.com/self.aspx/INDWAY-Integration%20Services/TryGenerics.zip

Thanks to Connected Systems for providing us this feature.

 

Cheers

M.R.ASHWINPRABHU

2 comments:

Unknown said...

This is very nice blog,and it is helps for student's.Thanks for info
Biztalk online training

Anonymous said...

This blog is so informative for providing valuable information about SMS API c# gateway integration. Thanks for sharing this blog.