Introduction - First things first!
When I first started learning BizTalk, I was looking for an article that could quickly show me how to build a simple orchestration (also known as "Business Process"). Unfortunately, I was unable to find one, so this is my attempt at demonstrating a simple orchestration. Please note that BizTalk Server 2004 is being used in the entire article.
Loan processing application - orchestration demo
Let us consider a simple loan processing request, where in a customer applies for a loan, and the loan request is either "APPROVED" or "REJECTED" based on the customer's ability to repay the loan.
Loan processing - business process
- A customer submits a loan processing request; we will call it a loan request.
- A business process determines whether the loan can be "APPROVED" or "REJECTED".
- A response is generated by the BizTalk which is sent back to the customer.
Creating the BizTalk project - "LoanProcessing"
Now let's start. Create a new BizTalk Server project in Visual Studio.
Step 1: In the Visual Studio .NET menu, select the File -> New -> "Blank Solution" and type the name "LoanProcessing
":
Step 2: In the Solution Explorer, right click on the solution name "LoanProcessing
" and select Add -> New Project. In the "Add Project" dialog box, for the type of the project, select "BizTalk Projects". Select the template "Empty BizTalk Project" and create a project named "Loan".
Building the schemas
We need to create two schemas; one is the "Loan Request" and other for "Loan Response". At the end of this section we would be ready with the following artifacts:
- LoanRequest.xsd
- LoanResponse.xsd
Loan request schema
Step 3: Right-click on the project in the Solution Explorer and select the "Add New Item" option. Then, select the item "Schema" and name it "LoanRequest
". When the schema shows up, rename the "Root" element to "LoanRequest
". After that, create the child elements: "RequestId
", "CustomerName
", "LoanAmount
", "AssetValue
", "DateRequested
":
Request Schema Elements
Property Name |
Property Value |
RequestId |
xs:string |
CustomerName |
xs:string |
LoanAmount |
xs:int |
AssetValue |
xs:int |
DateRequested |
xs:date |
Please look at the image below and confirm your schema file:
Loan response schema
Step 4: Right-click on the project in the Solution Explorer and select the "Add New Item" option. Then, select the item "Schema" and name it "LoanResponse
". When the schema shows up, rename the "Root" element to "LoanResponse
". After that, create the child elements: "RequestId
", "CustomerName
", "LoanAmount
", "Status
", "Comments
":
Response Schema Elements
Property Name |
Property Value |
RequestId |
xs:string |
CustomerName |
xs:string |
LoanAmount |
xs:int |
Status |
xs:string |
Comments |
xs:string |
Building the map
We need to build a map which would transform a loan request XML document into a loan response XML document. A map in BizTalk is a behind-the-scene XSLT file.
Step 5: Right-click on the project in the Solution Explorer and select the "Add New Item" option. Then, select the item "Map" and name it "LoanRequest-To-LoanResponse-Map
". Notice the file name convention used here, "SourceSchemaName-To-TargetSchemaName-Map".
Step 6: Click on the left link "Open Source Schema" and select "LoanRequest
". Click on the link "Open Destination Schema" and select "LoanResponse
". Complete the mapping as shown in the picture below:
- Select the "Scriptoid Function".
- Click on the property "Configure Functoid Script".
- Select C# as "Script Type", and copy and paste the code in the script function:
public string LoanProcessing(int loanAmount, int assetValue)
{
if ( loanAmount < assetValue)
{
return "APPROVED";
}
else
{
return "REJECTED";
}
}
Building the orchestration (also known as a "Business Process")
In an orchestration, a message is the unit of processing. A "message" will always be processed. A "message" can be of any XML schema type. In this project, we have defined two schemas, so ideally we would have two messages in this orchestration.
Step 7: Right-click on the project in the Solution Explorer and select the "Add New Item" option. Then, select the item "BizTalk Orchestration" and name it "LoanOrchestration
":
Step 8: Place three shapes on the "Orchestration Surface":
- Receive shape
- Transform shape
- Send shape
Step 9: Create two messages:
LoanReq
, and in the Properties Window, set the message type as "Loan.LoanRequest
".
LoanResp
, and in the Properties Window, set the message type as "Loan.LoanResponse
".
Step 10: Setting the properties for all the shapes:
- Select the Receive shape, and in the Properties Window, set the message type as "
LoanReq
" and "Activate
" as True
.
- Select the Send shape, and in the Properties Window, set the message type as "
LoanResp
".
- Select the Transform shape and set the properties as shown in the figure below:
Step 11: Create two ports (a receive port and a send port).
- Receive port: Right-click on the port surface, and select "New Configured Port", and give it a name "
ReceivePort
", leave all the default properties as it is in the wizard.
- Send port: Right-click on the port surface, and select "New Configured Port", and give it a name "
SendPort
", leave all the default properties as it is in the wizard.
Step 12: Strong name and deployment!!
- Create a key file using the "sn -k LoanKey.snk" in the Visual Studio .NET command prompt.
- In the Solution Explorer, right-click on the "Loan" Project Properties and select "Assembly" and specify the key file name.
- In the Solution Explorer, right-click on the "Loan" Project Properties and select "Deploy".
Step 13: Refresh - BizTalk Explorer and create send port and receive locations.
- Please refer to MSDN documentation on how to create send port and receive locations.
Step 14: Test the solution
- Place the input file in the receive location. Check the response in the output folder.
Quick takeaways
- Always set the
Activate
property to "true
" for the first Receive shape in the orchestration.
- The first step in an orchestration is to decide the number of messages flowing through the business process and then creating them.
- A BizTalk message is always associated with a schema (except in the case of un-typed messages).
- A BizTalk service needs to be re-started every time a deployment is done.