Microsoft KB Archive/320852

= HOW TO: Write a Visual Basic .NET Preprocessor for BizTalk Server =

Article ID: 320852

Article Last Modified on 11/14/2003

-

APPLIES TO


 * Microsoft BizTalk Server 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q320852



IN THIS TASK
SUMMARY
 * Create the Interop DLLs
 * Load the Interop DLLs into the Global Assembly Cache
 * Write the Preprocessor Code
 * Register the Assembly
 * Load the Assembly into the Global Assembly Cache
 * Process a Document with the Preprocessor in BizTalk Server



SUMMARY
This step-by-step article describes how to create a simple preprocessor for BizTalk Server by using Visual Basic .NET.

back to the top

Create the Interop DLLs
NOTE: In the following steps, you will run several commands from the Microsoft Visual Studio .NET command prompt. Visual Studio .NET environment variables are loaded with this command prompt. To open the Visual Studio .NET command prompt, click Start, point to Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt.

To create the Interop DLLs for the Btscomplib.tlb, the MSXML3.dll, and the AIComp.dll files, follow these steps:  Open a Visual Studio .NET command prompt, and then use the cd command to change directories to the \Program Files\Microsoft.NET\Primary Interop Assemblies directory. To create the strong name for the Interop DLL of Btscomplib.tlb, run the following command from the Visual Studio .NET command prompt:

sn -k Interop_btscomplib.snk

 To create the strong name for the Interop DLL of MSXML3.dll, run the following command from the Visual Studio .NET command prompt:

sn -k Interop_MSXML3.snk

 To create the strong name for the Interop DLL of AIComp.dll, run the following command from the Visual Studio .NET command prompt:

sn -k Interop_AIComp.snk

 To create a primary interop assembly wrapper, use the Type Library Importer (Tlbimp.exe) by running the following command from the Visual Studio .NET command prompt:

tlbimp &quot;C:\Program Files\Microsoft BizTalk Server\btscomplib.tlb&quot; /out:Interop_btscomplib.dll /namespace:Interop_btscomplib /asmversion:1.0 /keyfile:Interop_btscomplib.snk /primary

 To create a primary interop assembly wrapper, use the Type Library Importer by running the following command from the Visual Studio .NET command prompt:

tlbimp &quot;C:\Program Files\Microsoft BizTalk Server\AIComp.dll&quot; /out:Interop_AIComp.dll /namespace:Interop_AIComp /asmversion:1.0 /keyfile:Interop_AIComp.snk /primary

 To create a primary interop assembly wrapper, use the Type Library Importer by running the following command from the Visual Studio .NET command prompt:

tlbimp &quot;C:\WINNT\system32\MSXML3.dll&quot; /out:Interop_MSXML3.dll /namespace:Interop_MSXML3 /asmversion:1.0 /keyfile:Interop_MSXML3.snk /primary

</li></ol>

back to the top

Load the Interop DLLs into the Global Assembly Cache
To load the Interop DLLs into the Global Assembly Cache (GAC), run the following commands from the Visual Studio .NET command prompt:

gacutil /i Interop_btscomplib.dll

-and-

gacutil /i Interop_MSXML3.dll

-and-

gacutil /i Interop_AIComp.dll

back to the top

Write the Preprocessor Code
<ol> To create a Class Library project in Visual Basic .NET, follow these steps: <ol style="list-style-type: lower-alpha;"> Start Visual Studio .NET.</li> On the File menu, point to New, and then click Project.</li> Click Visual Basic Projects under Project Types, and then click Class Library under Templates.</li> In the Name box, type Preprocessor .</li> In the Location box, type C:\Preprocessor .</li></ol> </li>  In the Code window of Class1.vb, replace any existing code with the following code: Imports Interop_AIComp Imports Interop_btscomplib Imports System.Text Imports System.Runtime.InteropServices Imports System.EnterpriseServices Imports Interop_MSXML3

Public Class CustProcessor

Implements IBTSCustomProcess

Dim strChannelName As String Dim strDestID As String Dim strDestQualifier As String Dim strDocName As String Dim strDocSpecName As String Dim lOpenness As Long Dim strSourceQualifier As String Dim lPassThrough As Long Dim strSourceID As String

Sub IBTSCustomProcess_SetContext(ByVal pCtx As IBTSCustomProcessContext) Implements IBTSCustomProcess.SetContext

' NOTE: This sample only demonstrates how to obtain context information.

strChannelName = pCtx.ChannelName strDestID = pCtx.DestID strDestQualifier = pCtx.DestQualifier strDocName = pCtx.DocName strDocSpecName = pCtx.EnvelopeName strSourceID = pCtx.SourceID strSourceQualifier = pCtx.SourceQualifier lOpenness = pCtx.Openness lPassThrough = pCtx.PassThrough

End Sub

Sub IBTSCustomProcess_Execute(ByVal vDataIn As Object, ByVal nCodePageIn As Integer, _                                 ByVal bIsFilePath As Boolean, ByRef nCodePageOut As Object, _                                  ByRef vDataOut As Object) Implements IBTSCustomProcess.Execute

Dim xmlDom As Interop_MSXML3.DOMDocument

nCodePageOut = nCodePageIn

' File receive function only EventLog.WriteEntry(&quot;Preprocessor&quot;, &quot;Starting Preprocessor Test (BizTalk PreProcessor)&quot;, EventLogEntryType.Information) If bIsFilePath Then Dim bLoaded As Boolean xmlDom = New Interop_MSXML3.DOMDocument

' Load the data into the DOM. bLoaded = xmlDom.Load(vDataIn)

If bLoaded Then ' Return the XML to BTS. vDataOut = xmlDom.xml Else Err.Raise(vbObjectError + 1, &quot;BTSCustomProcess_Execute&quot;, &quot;Unable to load the document into the DOM&quot;) End If

xmlDom = Nothing Else Err.Raise(vbObjectError + 2, &quot;BTSCustomProcess_Execute&quot;, &quot;You can only use this BTSCustomProcess for FILE receive functions&quot;) End If       EventLog.WriteEntry(&quot;PreProcessor&quot;, &quot;Ending PreProcessor Test (BizTalk PreProcessor)&quot;, EventLogEntryType.Information) End Sub

<ComRegisterFunction> Public Shared Sub RegisterFunction(ByVal t As Type) Try Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(&quot;CLSID\\{&quot; + t.GUID.ToString.ToUpper + &quot;}\\Implemented Categories\\{20E8080F-F624-4401-A203-9D99CF18A6D9}&quot;)

Catch End Try End Sub

<ComUnregisterFunction> Public Shared Sub UnregisterFunction(ByVal t As Type) Try Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(&quot;CLSID\\{&quot; + t.GUID.ToString.ToUpper + &quot;}\\Implemented Categories\\{20E8080F-F624-4401-A203-9D99CF18A6D9}&quot;)

Catch End Try End Sub

End Class </li> To add references for the Interop_AIComp.dll, the Interop_btscomplib.dll, and the Interop_MSXML3.dll assemblies to the project, follow these steps: <ol style="list-style-type: lower-alpha;"> In Solution Explorer, right-click Preprocessor, and then click Add Reference.</li> Click Browse, and then locate the \Program Files\Microsoft.NET\Primary Interop Assemblies folder.</li> Click Interop_AIComp.dll, and then click Open.</li> Under Component Name, click System.EnterpriseServices.</li> Click Select, and then click OK.</li> Repeat steps 3c through 3e for the Interop_btscomplib.dll and the Interop_MSXML3.dll assemblies.</li></ol> </li> At the Visual Studio .NET command prompt, use the cd command to change directories to the C:\Preprocessor folder.</li> <li>To create the strong name for the Preprocessor assembly, run the following command from the Visual Studio .NET command prompt:

sn -k PreProcessor.snk

</li> <li> In the Visual Studio .NET IDE, right-click AssemblyInfo.vb, and then click View Code. Add the following Assembly attribute to the list of assembly entries in AssemblyInfo.vb: <Assembly: AssemblyKeyFile(&quot;C:\PreProcessor\Preprocessor.snk&quot;)> </li> <li>Save and then compile the project.</li></ol>

back to the top

Register the Assembly
To register the assembly, run the following command from the Visual Studio .NET command prompt:

regasm /tlb &quot;C:\PreProcessor\bin\Preprocessor.dll&quot;

back to the top

Load the Assembly into the Global Assembly Cache
To load the assembly into the Global Assembly Cache, run the following command from the Visual Studio .NET command prompt:

gacutil /i &quot;C:\PreProcessor\bin\Preprocessor.dll&quot;

back to the top

Process a Document with the Preprocessor in BizTalk Server
<ol> <li>In the BizTalk Messaging Manager, create a port to a file, and then create a channel to the port.</li> <li>In the BizTalk Administrator, create a File Receive function, point the File Receive function to the channel that you created in step 1, and then click Preprocessor.CustProcessor in the Preprocessor list.</li> <li> After this preprocessor processes a document, the preprocessor logs entries in the BizTalk Server Application event log. For example, the entries may appear similar to the following entries: <pre class="fixed_text">  Event Type:     Information Event Source:  PreProcessor Event Category: None Event ID:      0 Date:          3/31/2002 Time:          6:46:51 PM   User:           N/A Computer:      BIZTALKSERVER Description: Starting Preprocessor Test (BizTalk PreProcessor)

Event Type:    Information Event Source:  PreProcessor Event Category: None Event ID:      0 Date:          3/31/2002 Time:          6:46:51 PM   User:           N/A Computer:      BIZTALKSERVER Description: Ending PreProcessor Test (BizTalk PreProcessor) </li></ol>

Additional query words: Type Library to .NET Assembly Converter tlbimp

Keywords: kbhowtomaster KB320852

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.