How to Access an Orchestration variable in Map
Many times while developing BizTalk application there arises a need to access some message context properties or some variables from orches07ation in map. For message context properties you can manage with the help of message assignment shape, for example: filename of incoming message(received via file or ftp adapter) is to be passed to a field in destination message. Consider incoming message is declared as msgIncoming and outgoing message is declared as msgOutgoing and it has field as Receivedfilename,in that case:
- Mark the field ReceivedFileName as distinguished
- In message assignment shape, add following code:
Likewise any other message context property can be accessed provided that it is written in context either by adapter or pipeline, in above scenario if some other adapter is used then File.ReceivedFileName won’t be available as this property is only populated when file adapter is used. But what about orches07ation variable? Well there is no direct way to access it in map.
So how to access orches07ation variables in map?
This question is very frequently asked on forums, also I have received questions directly around it along with following questions(answers of all I intend to cover in this post):
1. How to pass ReceivedFileName in map/How to insert ReceivedFileName in database
2. How to cons07uct message using LoadXml Method
3. How to pass orches07ation variable in map
4. How to create map with multiple source to single destination
5. How to configure WCF-Custom adapter
6. How to generate schema from Table
6. How to generate schema from Table
To answer all questions above, have considered following scenario:
Scenario:
Order is received on file location and it is to be inserted in database along with FileName.
Creating the Solution:
Create Order table
Generate schema from Order table
Binding : sqlBinding as the database we are dealing is SQL Server
IntialCatalog : Demo as this is database which is to be connected and it holds the table we are dealing with
Server : “.” As database resides on same machine, if it was on other machine then it would have been that machine’s address.
Select con07act type: Client (Outbound Operations) as message is going out of BizTalk
Operations: Insert as data will be inserted in the table
- Select sqlBinding
- Select how you would connect to SQL
- Provide the database where the table reside against Initial catalog and on which server (here it is dot as database in on local machine)
- Click Connect
- Select outbound operation as data is inserted into SQL from BizTalk (outbound in reference to BizTalk), if we were to receive then it would have been Inbound operation
- Select the table and four operations will be visible
- Provide filename prefix (not mandatory) but it helps in managing and reading when number of generated schemas are more in a project
- As highlighted above, four files are added
Create supporting schema
To hold Orches07ation variable and context properties. In this schema add fields corresponding to the context properties and variables which you want to use in map, here as I am demons07ating only one context property so only one field in the schema.
And mark the fields as Distinguished, so as to make it available in message assignment shape to assign values to it
Create Orches07ation
1. Declare messages and variable
- Create three messages tied to their respect respective Schema
- XmlDoc variable of type System.Xml.XmlDocument
Why XmlDocument variable? The class "XmlDocument" is a super class for all XML messages, and hence it can hold any type of XML message and subsequently any type of orches07ation message.
2. Add Receive shape to receive Incoming Order
3. Add cons07uct shape with message assignment shape to cons07uct the msgOrches07ationVariables, here we use LoadXml method to cons07uct it.
Apart from Map, Message Assignment, using .Net, the fourth way to
cons07uct message is with the help of LoadXML method – which provides a
way to load the instance of schema of the message which is to be created
(with or without actual values)
Comments
Post a Comment