|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionIn this article, we'll see how to create and use a custom pipeline component in BizTalk Server 2004. Our component will receive a ZIP file, uncompress it, and send its contents to BizTalk Server. Although the article seems complicated, you'll see that create a custom pipeline component is quite a simple task. Our project will use a free Zip library, the ICSharpZipLib. This library can be found at the IC#Code web site. Creating a Custom PipelineA Custom Pipeline component is nothing more than a simple .NET DLL that implements a class with some predefined interfaces. This interface represents the layer between a .NET Program and then BizTalk Server. We'll start creating a new C# Class Library project called UnzipDisassembler. Now that we created the project, we need to add our references. The first reference we'll need is that to the ZIP Library. After downloading the latest version of it, add a reference to our project. After adding the reference to the Zip Library, we'll need a reference to a BizTalk Server library. This library can be found at the BizTalk Server install folder (\Program Files\Biztalk Server 2004, to be more precise). The name of this library is Microsoft.Biztalk.Pipeline.dll, it contains the basic interfaces we'll need to process the Zip file message. Coding the classNow, we'll start coding our custom pipeline component. We'll start creating the using System;
using System.IO;
using Microsoft.BizTalk.Component.Interop;
using Microsoft.BizTalk.Message.Interop;
using System.ComponentModel;
using System.Resources;
using ICSharpCode.SharpZipLib.Zip;
Now, we'll update the name of the class in the project. Change the default namespace UnzipDisassembler
{
/// <SUMMARY>
/// Summary description for Class1.
/// </SUMMARY>
public class UnzipDisassemblerComponent
{
public UnzipDisassemblerComponent()
{
//
// TODO: Add constructor logic here
//
}
}
}
Implementing the InterfacesTo create a custom pipeline component, we need to implement some default interfaces. If we want to create a generic pipeline component, we need to implement [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
[ComponentCategory(CategoryTypes.CATID_DisassemblingParser)]
[System.Runtime.InteropServices.Guid("
6118B8F0-8684-4ba2-87B4-8336D70BD4F7")]
public class UnzipDisassemblerComponent : IBaseComponent,
IDisassemblerComponent,
IComponentUI,
IPersistPropertyBag
{
public UnzipDisassemblerComponent()
{
//
// TODO: Add constructor logic here
//
}
}
Now that we've added the interfaces to the class, we need to implement them. We'll start with the IBaseComponentThe fist interface we'll implement is the
Right click the Each one of this properties returns some information about your custom pipeline component. The public string Description
{
get {
return "Componente de descompactação para Biztalk";
}
}
public string Name
{
get{
return "UnzipDisassemblerComponent";
}
}
public string Version
{
get{
return "1.0.0.0";
}
}
IComponentUIThis interface defines the behavior of the component in the BizTalk pipeline designed. We'll need to implement a method and a property. The public System.Collections.IEnumerator Validate(object projectSystem)
{
return null;
}
public System.IntPtr Icon
{
get
{
return new System.IntPtr ();
}
}
IPersistPropertyBagThe public void GetClassID(out Guid classID)
{
classID = classID = new Guid("6118B8F0" +
"-8684-4ba2-87B4-8336D70BD4F7");
}
public void InitNew()
{
}
public void Load(IPropertyBag propertyBag, int errorLog)
{
}
public void Save(IPropertyBag propertyBag,
bool clearDirty, bool saveAllProperties)
{
}
Note that the IDisassemblerComponentThis interface is the most important of our component. The public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
{
}
public IBaseMessage GetNext(IPipelineContext pContext)
{
return null;
}
Implementing the Unzip LogicThe unzip logic will be implemented inside the Stream strmZipFile;
IBaseMessagePart msgPart;
msgPart = pInMsg.BodyPart;
strmZipFile = msgPart.GetOriginalDataStream();
ZipInputStream oZipStream = new ZipInputStream(strmZipFile);
Note that we're creating a System.Collections.Queue qOutputMsgs = new System.Collections.Queue();
Now, let's go back to the ZipEntry sEntry = oZipStream.GetNextEntry();
while(sEntry != null)
{
MemoryStream strmMem = new MemoryStream();
byte[] aBytes = new byte[2047];
int inOffSet = 0;
int outOffSet = 0;
int iRead = oZipStream.Read(aBytes, 0, 2048);
while(iRead != 0)
{
strmMem.Write(aBytes, outOffSet, iRead);
outOffSet += iRead;
iRead = oZipStream.Read(aBytes, inOffSet, 2048);
inOffSet += iRead;
}
strmMem.Seek(0, SeekOrigin.Begin);
msgPart.Data = strmMem;
IBaseMessage outMsg;
outMsg = pContext.GetMessageFactory().CreateMessage();
outMsg.AddPart("Body",
pContext.GetMessageFactory().CreateMessagePart(), true);
outMsg.BodyPart.Data = strmMem;
qOutputMsgs.Enqueue(outMsg);
sEntry = oZipStream.GetNextEntry();
}
Note that to create an output message to BizTalk, we're using the context object that we received as a parameter. This context accesses BizTalk's Returning the messages to BizTalkNow, we need to implement the if(qOutputMsgs.Count>0)
return (IBaseMessage)qOutputMsgs.Dequeue();
else
return null;
Compiling the projectBefore we compile our project, we should change some of the properties of the project. The first project we need to change is the output path of the assembly. In order to work with BizTalk, custom pipeline components should be placed in a specific BizTalk folder (the \Program Files\Microsoft BizTalk Server 2004\Pipeline Components). The properties of the project should be as shown in the picture below:
After updating the project properties, build it. Creating a test projectNow that out pipeline component is ready, we need to test it. To do this, we'll create a new BizTalk project that will use our custom pipeline component. Add a new BizTalk Server project in our solution, and name it PipelineTest. In this project, add a new "Receive Pipeline" item and name in UnzipTest.btp. Open the UnzipTest.btp and check that the toolbox doesn't show our custom pipeline component. To add the component to the toolbox, select Add/Remove Items (right click on the toolbox). A new window will show up (like in the picture below). In this window, select UnzipDisassemblerComponent.
Now that we have our component in the toolbox, drag it to the disassemble stage of the pipeline. Below this component, drag a
Debugging the pipeline componentNow that our component is ready, we need to debug it. To debug a pipeline component, we'll need to use a tool that comes with BizTalk Server. This tool is called Pipeline.EXE, at it simulates the execution of a pipeline component for an input message. Open the project properties of the pipeline component project, and select the Debugging tab. In Debug mode, select "Program", and click the "Apply" button. In the property "Start Application", use the path to the pipeline.exe tool. The most common path is shown below: C:\Program Files\Microsoft BizTalk Server
2004\SDK\Utilities\PipelineTools\Pipeline.exe
In the command line, use the arguments below: C:\Labs\Work\BSCPipeline\UnzipTest.btp -d
C:\Order.zip -c -m C:\%messageid%.xml
The first parameter represents the path to the pipeline file that we created in the PipelineTest project (you need to provide the complete path for this to work). The -d parameter represents the input document we'll use. In our example, the input document is a .zip file. The last parameters -c and -m, represent the output options (-c represents that the output should be shown in the console, and -m shows the output path of the generated messages). After setting these parameters, set some breakpoints in the project and run it, you should see the complete steps of the execution of the pipeline. ConclusionAs you can see, the creation of a custom pipeline component for BizTalk Server 2004 is a simple task, it just requires some extra coding time. Hope you like the article! :)
|
||||||||||||||||||||||