BizTalk Scriptor Component AIC

BizTalk Scriptor AICs provide a much simpler implementation of the underlying functionality of the IPipelineComponent interface. If you are familiar with Microsoft Site Server 3.0 Commerce Edition and have used the Commerce Server Pipelines, you will be familiar with the Pipeline Scriptor Component. BizTalk Server has borrowed this technology from the Commerce Server. The Scriptor components are written in VBScript or Jscript and as such are interpretive. From performance consideration, you will not use Scriptor AICs in production deployment. In addition to the performance, all variables are of type variants and sometimes present a problem when integrating with applications requiring certain data types.

BizTalk Scriptor Components are great for quick prototype and debugging purposes. Because these components are interpretive, you do not have to compile the component each time you make changes. In this section, you see how easy it is to build a Scriptor component. On top of that, there is nothing to register in this case. BizTalk Scriptor Component is provided out of the box and is registered at the time BizTalk is installed. The script that you write is hosted in this component.

Building and Deploying a BizTalk Scriptor AIC

In this section we will build and deploy a simple Scriptor AIC. The AIC takes the incoming message and logs the message to a file. We will configure the AIC for the log file at deployment. In this case, we will swap out the IPipelineComponent AIC with the Scriptor AIC. However, instead of inserting the NewUserInfo into the SQL Server database, the Scriptor AIC simply logs the file into a directory. The following steps install a Scriptor AIC:

1.
Figure 17.16 shows the BizTalk Messaging Port and the list of Application Integration Components installed on my machine. Select the BizTalk Scriptor component from the list and click OK.

Figure 17.16. BizTalk Scriptor as an AIC.


2.
Figure 17.17 shows the port bound to the Scriptor AIC. Click OK and click Finish to close the Messaging Port Wizard.

Figure 17.17. Port bound to the BizTalk Scriptor AIC.


3.
Jump to the Advance configuration page of the channel and click on the Advanced button. Figure 17.18 shows the page Override Messaging Port Defaults. Click on the Properties button; the BizTalk Scriptor Properties dialog box appears (see Figure 17.19).

Figure 17.18. Advanced Channel Configuration—Override Messaging Port Defaults.


Figure 17.19. BizTalk Scriptor AIC property page.


  • Selecting the Scripting Engine—You have two options VBScript or JScript. For our case, we will select VBScript.

  • Configuration—In our case, we will specify the name of the log file we want the Scriptor AIC to write the content of the message to. The configuration information needs to be specified as a Name=Value pair, separated by “;". Name is important because the Scriptor AIC will be looking for a value for the Name specified. We have specified LogFileName as the Name and ..Chp17Exmp1outputMyDoc.xml as the Value.

  • Script Source—The script can be internal or external. If you select external, you have to provide the full path to the file that contains the script. My personal preference is to have the script external. This allows me to use an editor of my choice, and in addition I can use source code control to track changes. Listing 17.14 shows the content of the script file ..Chp17SourceCodeBTS_ScriptorCreateUser.txt.

Listing 17.14. Complete Source Code for Scriptor AIC
function MSCSExecute(config, orderform, context, flags)

On Error Resume Next

  Dim oFileSysObj, oTextStreamObj
  Dim strLogFileName
  Dim strDocument
  'get the log file name from the config Dictionary
  strLogFileName = config.value("LogFileName")

  'Create a file to write the in coming document
  Set oFileSysObj = CreateObject("Scripting.FileSystemObject")
  Set oTextStreamObj = oFileSysObj.OpenTextFile(strLogFileName, 2, True)

 if Err.Number = 0 then
   'get the in coming document from the orderform dictionary. The key that
   'has the document is working_data

   strDocument = Cstr(orderform.Value("working_data"))

   'Finally write the document
   call oTextStreamObj.Write(strDocument)

   oTextStreamObj.Close
   Set oTextStreamObj = Nothing
   Set oFileSysObj = Nothing

   'indicate success
   MSCSExecute = 1

 else

   'indicate failure
   MSCSExecute = 0
   Set oTextStreamObj = Nothing
   Set oFileSysObj = Nothing

 end if

end function

sub MSCSOpen(config)
    'optional open routine
end sub

sub MSCSClose()
    'optional close routine
end sub

We will briefly discuss the Scriptor AIC code here.

The function MSCSExecute() has four parameters. They are all dictionary objects except the flag. The third parameter MTS context is not available to the Scriptor component, and the flag is for backward compatibility. The first parameter config holds all the configuration information and the second parameter orderform holds most of the data, such as the working_data (the message itself), Document_Name, tracking_id, and others.

The line of code strLogFileName = config.value("LogFileName") extracts the value of the LogFileName key from the config dictionary object. The LogFileName is then used to create a file using the Scripting.FileSystemObject. Next we get the actual message from the orderform object in the line strDocument = Cstr(orderform. Value("working_data")).

The rest of the code writes the content of the message to the log file. Note the return value of the function MSCSExecute(). A return value of 0 is failure, and a return value of 1 indicates success. If you return 0 from this function, BizTalk Server detects this as a failure in the port and forces the document into the Suspended Queue.

The functions MSCSOpen() and MSCSClose() are optional and are not required for BizTalk Scriptor AIC.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset