现在阅读
First Footsteps with Orchestrations in BizTalk Server 2004
0

First Footsteps with Orchestrations in BizTalk Server 2004

由 ultracpy2018年1月26日

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

  1. A customer submits a loan processing request; we will call it a loan request.
  2. A business process determines whether the loan can be “APPROVED” or “REJECTED”.
  3. 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:

  1. LoanRequest.xsd
  2. 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 NameProperty Value
RequestIdxs:string
CustomerNamexs:string
LoanAmountxs:int
AssetValuexs:int
DateRequestedxs: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 NameProperty Value
RequestIdxs:string
CustomerNamexs:string
LoanAmountxs:int
Statusxs:string
Commentsxs: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:

  1. Select the “Scriptoid Function”.
  2. Click on the property “Configure Functoid Script”.
  3. 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”:

  1. Receive shape
  2. Transform shape
  3. Send shape

Step 9: Create two messages:

  1. LoanReq, and in the Properties Window, set the message type as “Loan.LoanRequest“.
  2. LoanResp, and in the Properties Window, set the message type as “Loan.LoanResponse“.

Step 10: Setting the properties for all the shapes:

  1. Select the Receive shape, and in the Properties Window, set the message type as “LoanReq” and “Activate” as True.
  2. Select the Send shape, and in the Properties Window, set the message type as “LoanResp“.
  3. 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).

  1. 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.
  2. 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!!

  1. Create a key file using the “sn -k LoanKey.snk” in the Visual Studio .NET command prompt.
  2. In the Solution Explorer, right-click on the “Loan” Project Properties and select “Assembly” and specify the key file name.
  3. 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.

  1. Please refer to MSDN documentation on how to create send port and receive locations.

Step 14: Test the solution

  1. Place the input file in the receive location. Check the response in the output folder.

Quick takeaways

  1. Always set the Activate property to “true” for the first Receive shape in the orchestration.
  2. The first step in an orchestration is to decide the number of messages flowing through the business process and then creating them.
  3. A BizTalk message is always associated with a schema (except in the case of un-typed messages).
  4. A BizTalk service needs to be re-started every time a deployment is done.

出处:https://www.codeproject.com/Articles/13222/First-Footsteps-with-Orchestrations-in-BizTalk-Ser

关于作者
ultracpy
评论

    你必须 登录 提交评论