Creating a many-to-one mapping in BizTalk 2010 is not straightforward. Such a map cannot be created simply by using menu options 'Add->New Item->Map'. But the work around to this problem is creating a many to one map using an orchestration.
This section covers the details of the project '
BizTalk_2_to_1_Mapping' attached with this tip.
A small insurance company offers only one type of insurance.
The output is required to be combined data of customer and his/her insurance details.
The interest rates will vary depending on whether it is a single or bulk customer. The premium to be paid will depend on unit premium and the premium payment term.
There are 2 input schemas. First is CustomerDetails.xml.
Second is InsuranceDetails.xml.
Output is formatted using the schema CustomerInsuranceDetails.xml.
Since we cannot create many-to-one map directly, add new orchestration. The incoming messages have to be related in some way, so that they are consumed by the correct instance of the orchestration. In this situation, we are using a correlation on property '
BTS.ReceivePortName', hypothesis being only one file of each file will come per day. Note that both the messages are received on the same logical port.
But, in actual scenarios, you should use some kind of promoted property, unique to both the messages, to create correlation between the messages.
Double click the Transform shape to edit it. Choose 'New Map' option. In the Source message selection drop-downs, select the messages referencing
InsuranceDetail schemas. In output message selection drop-down, select the message referencing to the
CustomerInsuranceDetails schema. Creating map from orchestration's Transform shape allows you to select multiple input schemas.
On clicking OK, the mapper will come up, with the newly created map, without any links. Add functoids and links to implement required mapping logic.
Testing the Application
- Sign the assembly / assemblies
- Build and deploy the solution from Visual Studio
- Configure on BizTalk Management console. Create One receive port, with 2 receive locations. Create a send port. Configure the orchestration for host, and ports. Start the application, restart the host.
- Generate XML instances of customer and insurance schemas, and put in corresponding locations. Check the output.
This is only a reference article. In actual developments environments, you should consider adding exception handling, logging, schema verification, time-out, etc.
- It is a best practice to maintain separate projects for orchestrations, maps, schemas, pipelines, etc. under a solution. In such scenario, the map created using orchestration will be created in the project for orchestrations, and the namespace will also be the same as that for orchestrations. So, remember to move the map to the mapping project and update the namespace accordingly. In the attached code, this step was not needed as there is a single project for sake of simplicity.
- If the input schemas are changed (so that the xpath expressions for links in the map will be affected) after map/transform creation, the map will not be loaded properly. In such case, instead of creating the whole map all over again, open the map in some text/code editor, and find and fix the affected xpath expressions for the links. Do not forget to create backup, as minor mistakes can render the transform useless.
Reloading the schema does not work here, as you can reload only one schema.
- 6th March, 2015: Initial version