Home > Articles > Programming > Windows Programming

This chapter is from the book

This chapter is from the book

Creating a Managed AIC Component

Creating a managed Application Integration Component (AIC) is similar to creating a managed component called from a COM client. Chapter 17, "Application Integration Components," discussed two BizTalk Messaging COM AIC interfaces. The first implements the IBTSAppIntegration interface; the second implements the IPipelineComponent interface. The IBTSAppIntegration AIC consists of a lightweight model that requires a single interface and consists of a single method, ProcessMessage, as its entry point. The ProcessMessage public method accepts a single parameter, the document string. This section discusses and demonstrates the use of the IBTSAppIntegration interface in a managed C# component. In this section we are going to create a simple C# AIC that accepts an XML document and then persists it to a local file directory.

Creating the DotNetAIC C# AIC

Creating a managed .NET AIC isn't difficult; however, a few concepts are useful to know prior to tackling the task of developing one. First, all AIC IBTSAppIntegration components must reference the BTSComponentsLIB.dll COM DLL to implement the interface. Because our AIC is managed by the CLR, it will need to reference the COM interface using a wrapper object called the Runtime Callable Wrapper (RCW). This type of wrapper object was used earlier in the chapter to reference the COM ADO DLL in the BankVB Visual Basic .NET component we created. The wrapper is automatically created for you in Visual Studio .NET when you add a reference to the DLL.

Second, when installing AICs, you must properly register them so that Microsoft BizTalk Server 2002 can identify them. The component must be registered with the category IDs for a pipeline component and for the specific type of pipeline component, in this case application integration. You can register the component manually using a registration file or by creating and installing the AIC in a COM+ application. In the C# AIC example, we register the managed object as a COM+ application using the System.EnterpriseServices ServicedComponent interface as we did earlier in the BankVB example.

The steps required to create, compile, and register the DotNetAIC C# AIC example in this section are listed below.

  1. Create two strong name .snk key files using the sn.exe command-line utility.

  2. Create an assembly for the btscomplib.tlb type library and sign it with a strong name key using the tlbimp.exe command-line utility.

  3. Reference the BTSComponentsLib assembly and System.EnterpriseServices namespace in the project references.

  4. Set the appropriate declarative attributes to assign the EnterpriseServices namespace attributes and COM class GUIDs.

  5. Set the strong name key and register the DotNetAIC component for COM interop using the C# project properties dialog.

  6. Compile or build the strong-named managed class.

  7. Register the DotNetAIC object using the regsvcs.exe command-line utility to update the COM+ catalog.

  8. Configure BizTalk Messaging to test the DotNetAIC.

In the following sections, we will walk through each of the preceding steps. After the component has been created, we will then test it using BizTalk Messaging. The test application will pick up a document from a local file directory and call a channel bound to a port that has a transport of type AIC.

Creating the C# Class Library

To create the new class library, add a new C# project named DotNetAIC to the BTSDotNet Visual Studio .NET solution we've been working with. To accomplish this, select the BTSDotNet solution in the Solution Explorer and right-click. In the pop-up menu that appears, select Add, New Project from the menu and then select the Visual C# Projects Class Library project and name it DotNetAIC. Visual Studio .NET automatically creates a class file named class1.cs for you. This project will consist of a single class file named DotNetAICtoFile.cs. To rename class1.cs, select it in the Solution Explorer and right-click. In the pop-up menu that appears, select the rename menu option and rename the file to DotNetAICtoFile.cs as displayed in Figure 14.24.

Figure 14.24 The BTSDotNET solution with the C# AIC project.

The C# AIC accepts a document from the BizTalk Server Messaging Engine as a string and then saves it as an XML document named Output.xml in a local file directory named C:\btsdotnet\AICDeploy\Reply.

Creating Strong Name Keys

The DotNetAIC class requires the use of two strong name key files. One will be used to sign the BTSComponentsLIB assembly, and the other will be used to sign the DotNetAIC. The DotNetAIC file must be signed to enable registration as a COM+ component. The BTSComponentsLIB assembly must be signed to be referenced from an assembly that is signed, in this case the DotNetAIC assembly. We are going to create the keys using the sn.exe command-line utility located in the \Program Files\Microsoft Visual Studio .NET\FrameworkSDK\bin directory of your local machine.

Note

To create the .snk files using this utility, you must either add this location to your system file path or specify full pathnames.

The two key files will be named btstlb.snk and BTSNetAIC.snk. To create them, type the following at the command prompt sn –k btstlb.snk and sn –k BTSNetAIC.snk. Then add the two files to the DotNetAIC project by dragging them into the Solution Explorer under the root of that project's folder.

Next we need to create and sign the BTSComponentsLIB assembly with the btstlb.snk that's been created.

Creating and Signing the BTSComponentsLIB Assembly with a Strong Name Key

To reference the COM type library from a C# project, we need to first wrap that object in a RCW. To create the wrapper, we will use the tlbimp.exe command-line utility located in the \Program Files\Microsoft Visual Studio .NET\FrameworkSDK\bin directory of your local machine. The tlbimp.exe utility also allows you to sign the assembly when you create it. To create and sign the assembly, open a command-line prompt and navigate to the \Program Files\Microsoft BizTalk Server directory to locate the btscomplib. tlb type library file. Then type the following on the command-line prompt tlbimp btscomplib.tlb /keyfile:(localfile path)\btstlb.snk. This creates an assembly named BTSComponentsLib.dll that will be added in the next section as a reference in the DotNetAIC project.

Note

This line of script assumes that the .NET directory has been added to your file path. The source code on the publisher's Web site has copies of the command-line utilities in a subdirectory named Utils. There are also batch files created to assist with the command-line statements. It is sometimes easier to move these files into a single directory when running the utilities, as was done in the example on the publisher's Web site.

Adding References to the C# Project

The AIC managed component references three external objects: the System.xml and System.EnterpriseServices namespaces and the RCW named BTSComponentsLIB.dll that we just created. To add these references to the project, select the References folder in the DotNETAIC project and right-click. In the pop-up menu that appears, select the Add Reference menu item. Then navigate to the .NET tab and select the System.xml .NET and System.EnterpriseServices namespaces. Next, navigate to the COM tab and select the BTSComponentsLIB.dll file using the Browse button to navigate to and select the DLL from the directory you created in the previous section. Then add references to both in the source code using the Using statement as displayed in Listing 14.12.

Note

In C#, the Using statement is equivalent to the Imports statement and allows you to avoid fully qualifying methods in the namespace.

Creating the C# Business Logic

When creating a managed AIC, you must remember two important items. First, because AICs are instantiated by a COM+ application object named the BizTalk Messaging Engine, the managed AIC must be exposed as a COM object using a COM callable wrapper (CCW). Second, you must also ensure that the managed object is registered as a pipeline component. In the DotNetAIC example, we accomplish this by adding the appropriate COM+ declarative attributes to the DotNetAIC class file. We also implement inheritance from the ServicedComponent interface to enable the registry of the managed component as a COM+ application. In Listing 14.12, notice that the public class AICtoFile inherits from both the ServicedComponent and IBTSAppIntegration interfaces. Also notice a reference to the GUID attribute to ensure its uniqueness when registered with COM. You can create the GUID using the Create GUID tool in Visual Studio .NET.

Listing 14.12 shows the code for the C# AIC.

Listing 14.12 The DotNETAICtoFile.cs File

using System;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
using System.Xml;
using BTSComponentsLib;
hhh
namespace CSharpBTSAIC
{
  // Summary description for AICtoFile.

  // Guid attribute ensures same Guid is used for all 
  // compilations, similar to binary compatibility in VB6
  [Guid("1AA73916-FB97-4049-B1AF-DF6BBB43CDB2")]
  // BTSInterop Inherits ServicedComponent and Implements 
  // IBTSAppIntegration
  public class AICtoFile: ServicedComponent, IBTSAppIntegration
  {
    public AICtoFile()
    {
      //
      // TODO: Add constructor logic here
      //
    }

    // This means that the transaction governing the object 
    // will automatically SetComplete() if the method call 
    // returns normally. If the method call throws an exception,
    // the transaction will be aborted
    string IBTSAppIntegration.ProcessMessage(string strDocument)
    {
      // Write the Input XML to a file
      XmlDocument xmlDoc = new XmlDocument();
      xmlDoc.LoadXml(strDocument);
      xmlDoc.SelectSingleNode("BTSAICRoot/MessageText").InnerText = 
_"Message from AIC";
      xmlDoc.Save(@"C:\btsdotnet\AICDeploy\Reply\Output.XML");

      // Simply return the Input as Output
      return strDocument;
    }
  }
}

The ProcessMessage method's business logic creates a new instance of an XML document and then saves the contents of the input string strDocument to a file named output.xml file.

Note

To keep things simple, the pathname is hard-coded into the example.

To add the business logic to the DotNetAIC.toFile.cs files in the DotNetAIC C# project, open the .cs file in Visual Studio and add the source code displayed earlier in Listing 14.12.

Compiling and Registering the Component

To register a managed object with COM+, it must be signed with a strong name.

Earlier we created two .snk key files, one to sign the BTSComponentLib.dll file and the other to sign the DotNetAIC managed component. To accomplish this, we need to tell Visual Studio .NET that we want to compile this project for COM interop with a strong name key. First, select the project in the Visual Studio .NET Solution Explorer and right-click, selecting the Properties menu option. In the dialog that appears, select the Common Properties folder's General option and reference the key filename in the Wrapper Assembly Key File configuration setting as displayed in Figure 14.25.

Figure 14.25 Setting the C# .NET strong name key file properties.

Next, navigate to the Configuration folder's Build menu option and set the Register for COM Interop value equal to True as displayed in Figure 14.26.

The COM Interop property creates the CCW and type library automatically for us when we compile the project. After the component is successfully compiled, run the .NET Framework command-line utility regsvcs.exe to create and register the object with COM+. To accomplish this, open the command window, navigate to the \BTSDotNET\ CSharpBTSAIC\bin\Debug directory, and type regsvcs dotnetaic.dll. Then verify its registration by opening the COM+ MMC. If an application named CSharpBTSAIC is present, it has been successfully registered.

Figure 14.26 Setting the C# .NET COM Interop property.

Note

The .NET command-line utilities location is not usually found in your local system path. The utilities are located in the c:\Program Files\Microsoft.NET\ Framework SDK\bin directory. You might need to include their location in your local path or fully qualify your references to the utilities.

BizTalk Messaging AIC Setup

To test the managed AIC, we are going to create a simple BizTalk Messaging example. The messaging example processes an XML document named BTSAICInstance.xml using a BizTalk Server file receive function. In the DotNetAIC example, we are going to create a new BizTalk Messaging organization named DotNETAIC and a new document named BTSAIC. The document specification will be stored in a Web Dav directory named Bank. The BTSAIC.xml document specification is displayed in Figure 14.27 in the BizTalk Editor.

To configure BizTalk Messaging, we need to complete the following steps. Each of these steps is described in detail later in this section.

  1. Create an XDR schema using the BizTalk Editor and save it to a WebDav repository named Bank.

  2. Create a new Organization named DotNetAIC.

  3. Create a new Port to an Organization named To BTS AIC using the BizTalk Messaging Manager.

  4. Bind the Port to a Channel from an Organization named From AIC Test that has inbound and outbound documents set to the BTSAIC document. The Port will have a transport of AIC that will reference the C# DotNetAIC.dll AIC created earlier.

  5. Create a file receive function using the BizTalk Administration console that will pass .xml files to the From AIC Test Channel.

  6. Test the AIC by dropping an instance of the BTSAIC document into the receive directory.

Figure 14.27 The BTSAIC.XML BizTalk document.

To configure BizTalk messaging, begin by creating the BTSAIC.xml BizTalk XDR schema using the BizTalk Editor and save it to a new WebDav folder named Bank. The schema can be created by hand or downloaded from the publisher's Web site. After you have created and saved the schema, open the BizTalk Messaging Manager and create a new document definition that references this schema in the repository and name the document BTSAIC. Then create a new Organization and name it AIC Test.

Next, create a new Port to an Organization and name it To BTS AIC. In the Messaging Port Wizard Destination Organization dialog that appears, select the AIC Test organization using the Browse button next to the Organization option. Then set the Primary transport type to AIC using the Browse button next to the Primary Transport Address option. In the dialog that appears, select AIC and then use the Browse button to select the CSharpBTSAIC.AICtoFile component. In the final wizard step, select Create a Channel for This Messaging Port and specify the From an Organization channel type.

Note

When you select the transport type of AIC, a dialog appears asking you to select a component from a list of registered AICs. If the C# component is not listed in the dialog, it has not been properly registered. To verify that it is registered, first check to see that the COM+ application exists. If it does, delete it manually using the COM+ MMC, recompile the managed object, and rerun the regsvcs.exe command-line utility.

The port will be bound to a channel named From Test AIC with the inbound and outbound documents set to the BTSAIC XML document created earlier.

In the New Channel Wizard that appears, name the Channel From DOTNETAIC and click Next. In the Source Organization dialog that appears, select the AIC Test organization and click Next. In the Inbound Document dialog that appears, select the BTSAIC document using the Browse button and click Next. Then select the BTSAIC document for the outbound document as well. The remainder of the wizard steps should keep the default settings.

The BizTalk file receive function will be configured to process all .xml files in the \BTSDotNet\AICdeploy\Submit directory. The channel also will be exclusively specified to From DOTNET AIC channel. To create the receive function, open the BizTalk Server Administration console and select the Receive Functions folder under the BizTalk Server Group and right-click. In the pop-up menu that appears, select the New File Receive Function menu option. In the Add a File Receive Function dialog that appears, name the function AIC Test, set the File Types to Poll for to *.xml, the Polling Location to \BtsDotNet\AICDeploy\Submit, and then click the Advanced button. In the Advanced Receive Function Options dialog that appears, select the From AIC Test channel in the Channel Name drop-down list and save the function.

To run the example, copy the BTSAICInstance.xml file from the \BTSDotNet\Docs directory to the \BTSDotNET\AICDeploy\Submit directory. The file receive function should pick up the file, executes the managed AIC, and then places the Output.xml file in the \BTSDotNet\AICdeploy\Reply subdirectory.

Note

The BTSAICInstance.xml document can be downloaded from the publisher's Web site or created using the BizTalk Editor.

Note

This example assumes a basic understanding of BizTalk Messaging. To learn more about BizTalk Messaging, refer to the chapters on BizTalk Messaging and/or the appropriate BizTalk Server documentation.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020