Using Dynamic Maps in BizTalk (from codeproject)

Source: Internet
Author: User
Tags biztalk
ArticleDirectory
    • Step 2: signing the DLL with a key
    • Step 5: Testing and Output
    • Step 8: a few notes on the output
    • Gotcha's
    • Exceptions
Introduction Dynamic Map S

If you have used Map S in Biztalk , By now, you must know that Map S are used to transform an XML message into another format. I do not intend to go into the details about Biztalk Map S here, but in essence, Map Is a transformation on your existing data to the output format you desire. In this article, I will adjust strate an interesting feature called Dynamic Map S in Biztalk . If you are a C ++ fan like me, you wocould be amazed at the power of polymorphism and how a call to a function, say Shape. Draw () , Differs with each derived class Shape Like Arc , Square , Or Circle . So I don't have to explain why Dynamic Map Ping is important.

Quite often inBiztalk, You come into SS scenarios where you need to transform a message to an output format, which you can decide only after you know some information which is contained in the message itself, like destination recipient. this can be achieved by usingMapS in the ports itself, but as the number of Parties grow and your exception handling requirements kick in, this route has some limitations. This is whereDynamic MapPing inside orchestrations make sense.

Scenario

For this exercise, I am building an orchestration which identifies the destination party and loads the correspondingMapAnd sends the message to the intended recipient after the desired transformation. For this example, I have two parties ABC and XYZ.

A bird's eye view of the steps

These are the steps for implementing ourDynamic MapS. I am assuming a working knowledgeBiztalkFor the solution below, as the concept is what I intend to your strate. You can skip these steps by downloading the source from abve.

    • CreateBiztalkProjectMapS.
    • Create all Schemas andMapS.
    • Create an orchestration project.
    • Identify the Party and loadMapSDynamicAlly.
    • Set the destinationDynamicAlly and route the message.
    • Deploy and GAC the DLL.
    • Testing.
Getting down to business ..

I have broken down the process into a series of logical steps.

Step 1: Creating Your Schemas and Map S project

You need to create a schema andMapS project. I have all myMapS and schemas in a project calledDynamic MapS. I have added three Schemas to the project.

    • The generic schema (common input schema)
    • ABC Schema (for my party ABC)
    • XYZ Schema (for my party XYZ)

The details of the three schemas are as below. The input schema comes in with some basic information. The output schemas differ for the two parties ABC and XYZ. The three schemas are shown below.

Right click onSubscriberinfoIn the genericschema and do a quick promotion. This will add a property schema toBiztalkProject.

Now we build the twoMapS. BothMapS use some basic information from the sources schema, and add some additional information on the output side. I have usedTimeFunctoid to get the submission time.

Step 2: signing the DLL with a key

You need to have a strong name for this Assembly to get it loaded in the toolbox. So create a strong name and sign it. Once you have the strong key generated, reference that inAssembly keyFile value in the project properties.

Step 3: Compile and deploy Map S project

From project properties in the Solution Explorer window, deploy the project. Check in GAC to see if the DLL is deployed. Note down the public key token from the file properties in GAC.

Step 4: Build Dynamic Map S orchestrations

Add a newBiztalkProjectOrchestrationforDynamicMapS. Create a New orchestration and name itOrch _DynamicMapS. In the orchestration View window, create the following variables and messages. Set the value as in the table below. Leave the rest of the values as their default values.

Message/variable Identifier Type Comments
Message Generic_in DynamicMapS. genericinschema The incoming message
Message Message_out System. xml. xmldocument The outgoing message
Variable Subscriberinformation System.String Promoted subscriber info
Variable TMap System. Type TheMapValue

The orchestration built looks as in the figure below. The outline of steps is detailed below. You can download the source and follow the steps conceptually.

  • Add a receive PortReceive_genericmessageWhich acceptsGeneric_inMessage declared above.
  • Add an expression shape identify subscriber and set the expression value as below: collapse | copy Code
     subscriberinformation = generic_in (  dynamic   Map   S. propertyschema. subscriberinfo); 
  • Add a decide and check ifSubscriberinformation ="ABC"OrSubscriberinformation ="XYZ", And a branch for termination.
  • Add an expression shape and name it SetMap And put the value.

    Change the Public Key token value to the value you noted down previusly.

    Collapse | Copy code
     
    TMap= System. type. GetType ("DynamicMapS.Map_ ABC,DynamicMapS, version = 1.0.0.0, culture = neutral, publickeytoken = f85be9e4dd36fb1d");
  • Add a message shape and doDynamicTransformation andDynamicAlly set the send port. These are the magic lines:Collapse|Copy code
    Transform (message_out) = TMap(Generic_in );Dynamic_ Send (Microsoft. xlangs. basetypes. Address) ="File: // C: \ ports \ ABC \ % messageid %. xml";
  • In the second branch for subscriber xyz, we set Map ToMap For XYZ and change the public key. Collapse | Copy code
     
    TMap= System. type. GetType ("DynamicMapS.Map_ Xyz,DynamicMapS, version = 1.0.0.0, culture = neutral, publickeytoken = f85be9e4dd36fb1d");
  • now we need to construct the message like ABC's. alternately, You can construct the message in the expression shape directly, but you wowould need to add the construct keyword. collapse | copy Code
     construct message_out {transform (message_out) = T   Map   (generic_in );   dynamic   _ Send (Microsoft. xlangs. basetypes. address) =  "   file: // C: \ ports \ XYZ \ % messageid %. XML " ;}
  • Add a send port which sends out a message of TypeSystem. xml, And use that to send the transformed file to your desired destination.
  • Compile and deploy the project.

Note: in essence, what we have done in the step above is to use the Reflection Feature in. NET and find the type ofMap. Then we use the variable and invoke the transformation by usingBiztalkInternal keywordTransform.BiztalkDoes all the hard work of loading the AssemblyDynamicAlly for our use and unloading the Assembly later, and all that plumbing that you otherwise need to write. Don't you loveBiztalkNow?

Step 5: Testing and Output

You can drop the two test files and you will get two different outputs for the same file based on changing the subscriber.

I have the inputs and outputs as below:

    • Input File for party ABC

    • Output for party ABC

    • Input File for party XYZ

    • Output for party XYZ

Step 8: a few notes on the output

The output is self explanatory, and you will notice that for identical inputs should t for the party name, the output was different based onMapS used. We usedTimeFunctoid to generate the time, and the other values came from fixed strings. and last but not the least, I confess, I am not 22 as the example file indicates or misleads, way older than that! My wife was quick to point that one out.

Points of interest

Although in this example we have used a simple decide shape to figure out whichMapTo load, in real life implementations, this cocould be a database helper class which returns the name ofMapAssembly from a SQL database or a similar design. This design is useful since you can add moreMapS and systems even after the original system has gone live. This is possible because you can add a new subscriber into the database and have a new DLL with the corresponding schema andMapS. This provides a loose-coupling which is highly desired in these scenarios.

Gotcha's

In the Declaration of the VariableTMap, I cocould not get it to be definedSystem. TypeFrom the dropdown. I had to open. OdxFile in notepad and set it manually after choosing a random type initially.

Exceptions

A very common exception wocould be:

Collapse | Copy code
 
Error in accessing the part data or one of its fragments. The part or fragment may not exist in the database.

when this happens, make sure you have both the Assemblies deployed and they are present in the GAC. also check that the ports are created and the receive port uses an XML transmit pipeline and the Send Port uses a pass-through transmit pipeline. if that did not solve the problem, Ping me at the BizTalk cafe forums . I wocould be gglad to take a look.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.