Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

BizTalk 2010 Recipes : Document Mapping - Calling Compiled Assemblies

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3/29/2011 10:41:53 AM

1. Problem

You need to access logic contained within an external assembly while transforming a message via a BizTalk Server map. The logic contained within the assembly cannot and should not be embedded within the map.

2. Solution

Create a map that uses the BizTalk Server Scripting functoid's ability to call external assemblies. The following steps outline the procedure:

  1. Click the toolbox, and click the Advanced Functoids tab. On the map surface, between the source and destination schemas, drag and drop a Scripting functoid. This functoid's input and output values are dependent on the logic contained within the Scripting functoid.

  2. Connect the left side of the Scripting functoid to the appropriate source data elements or records. In this solution, no source data elements are used.

  3. Configure the Scripting functoid.

    1. While the Scripting functoid is highlighted on the mapping grid, right-click the functoid, and select Configure Functoid Inputs.

    2. In the Configure Scripting Functoid dialog box, on the Script Functoid Configuration tab, select External Assembly for Script Type and the appropriate assembly, class, and method for Script Assembly, Script Class, and Script Method, as shown in Figure 1. Then click OK.

      Figure 1. Configuring a Scripting functoid with an external assembly

      NOTE

      You must add a reference to the external assembly to the Visual Studio project containing the map for it to be available in the Configure Functoid Script dialog box. The external assembly must also be placed in the GAC.

    3. To pass in a parameter, click the ellipsis to the right of Input Parameters in the Properties window.

    4. In the Configure Functoid Inputs dialog box, on the Functoid Inputs tab, create or order the appropriate input parameters for the method specified in step 2, as shown in Figure 2, and then click OK.

    Figure 2. Configuring the Scripting functoid's input parameters
  4. Connect the right side of the Scripting functoid to the appropriate destination data element or additional functoid (if further logic needs to be applied to the data).

3. How It Works

In this example, the functoid in the map determine whether there is enough time before the event for the tickets to be mailed to the purchaser. The XML snippet shown in Listing 1 represents one possible instance of the source schema.

Example 1. Sample Source Instance for the Scripting Functoid Example
<ns0:TicketRequest xmlns:ns0="http://Mapping.TicketRequest">
<EventName>Chelsea vs. Arsenal</EventName>
<EventDate>08/06/2010</EventDate>
<Venue>Stamford Bridge</Venue>
<NumberOfTickets>2</NumberOfTickets>
<PurchasedBy>George Murphy</PurchasedBy>
<MailTicketFlag>True</MailTicketFlag>
</ns0:TicketRequest>

Based on this source XML, the map will produce the XML document (assuming that the current date is prior to August 4, 2010) shown in Listing 2, with the MailedTicketFlag appropriately set.

Example 2. Sample Output Instance for the Scripting Functoid Example
<ns0:TicketOrder xmlns:ns0="http://Mapping.TicketOrder">
<Title>Chelsea vs. Arsenal</Title>
<Date>08/06/2010</Date>
<Venue>Stamford Bridge</Venue>
<NumOfTickets>2</NumOfTickets>
<TicketHolder>George Murphy</TicketHolder>
<MailedTicketFlag>True</MailedTicketFlag>
</ns0:TicketOrder>

This example demonstrates one of the many reasons why external assemblies may need to be called from a BizTalk Server map. Here, the external assembly provides access to a configuration value. This value is held in a configuration file (but alternatively could be held in a database or other data store), which is updated over time by system administrators and business analysts. For the purposes of this example, the following configuration value was used.

<add key="MinimumDaysAdvanceForMailedTickets" value="-2" />

The value of −2, which represents the minimum number of days required to mail tickets to a purchaser, is added to the EventDate element (by the Add Days functoid), resulting in a date value two days prior to the event (08/04/2006 in this example). The current date (supplied by the Date functoid) is then compared to the calculated date value (by the Less Than logical functoid) to determine if there is enough time to mail the purchased tickets. Finally, if there is ample time to mail the tickets, and the source document indicates the purchaser requested tickets to be mailed, the MailedTicketFlag element in the destination message is set to true.

The benefit of having the MinimumDaysAdvanceForMailedTickets value stored in a file external to BizTalk, as opposed to being hard-coded within the actual map, is that a change to the value does not require a redeployment of BizTalk Server artifacts for the modification to be applied. Additionally, by encapsulating the custom logic in an external assembly, any changes to that logic will require only that the external assembly is rebuilt and redeployed to the GAC. No changes to the BizTalk Server environment (aside from a BizTalk service restart to immediately apply the changes in the redeployed custom assembly) are required. Implementing this logic in an external assembly has the additional benefits of allowing reuse of the logic, minimizing code maintenance, and providing access to the debugging utilities within Visual Studio.

NOTE

You can step into the external assembly in debug mode by running the external assembly solution in Visual Studio in debug mode, attaching to the process of the Visual Studio solution containing the BizTalk Server map, and testing the map.

In addition to using a generic external assembly, a custom functoid could also have been used to implement the configuration value retrieval logic. It is important to consider the differences between the two options prior to selecting your design. The main benefit of using a custom functoid is that the assembly is hosted within the BizTalk Server environment. The actual assembly file is located within the BizTalk Server program file directory, and the functoid can be added to the Functoid Toolbox within the development environment. Using generic external assemblies is sometimes a requirement, however, such as when the existing logic contained within them needs to be accessed directly (without modification to the source code or assembly location). This may be the case when using third-party or proprietary assemblies, where you do not have access to the source code.

Other common examples of logic contained in external assemblies are complex database-retrieval mechanisms, calculations above and beyond what is possible with the out-of-the-box mathematical functoids, and complex date and string formatting.

Care should be taken with regard to data types for values passed into and out of external assemblies. For example, if a source document element having a data type of xs:int is used as an input parameter for a method contained in an external assembly, it will be passed as an integer. Likewise, if the output from an external assembly is used to populate a destination document element having a data type of xs:int, it should be returned as an integer.

Other -----------------
- BizTalk 2010 Recipes : Document Mapping - Creating Functoid If-Then-Else Logic
- Windows Server 2008 Server Core : Managing Directory Services Using the WMIC NTDomain Alias
- Windows Server 2008 Server Core : Securing the System - Converting Event Trace Logs with the TraceRpt Utility
- Leveraging Social Networking Tools in SharePoint 2010 : Components of My Sites (part 2) - Using Bookmarklets
- Leveraging Social Networking Tools in SharePoint 2010 : Components of My Sites (part 1) - Creating and Exploring a My Site
- Leveraging Social Networking Tools in SharePoint 2010 : User Profile Job Review
- Leveraging Social Networking Tools in SharePoint 2010 : Mapping a SharePoint Profile Field to Active Directory
- BizTalk 2010 Recipes : Document Mapping - Using the Date and Time Functoids
- BizTalk 2010 Recipes : Document Mapping - Creating a Custom Functoid
- Windows Server 2008 R2 : Deploying and Using Windows Virtualization - Using Snapshots of Guest Operating System Sessions
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server