Every repository with this icon (
Every repository with this icon (
Old API Examples
The original (or “old”) API was created during the first couple of releases of the library. It is still supported and works just fine, but it can be a bit more verbose than the new, “simple” API and it is definitely less readable. It’s worth noting that the new API is completely written on top of the old API, so it will always be a supported option.
Using the API
To use the old API you need to import the namespace:
using Winterdom.BizTalk.PipelineTesting;
Creating a new Pipeline
To instantiate a pipeline, you need to use the PipelineFactory class. You can either create an empty pipeline, or an instance of an existing, pre-compiled BizTalk pipeline class.
Here’s an example:
using Microsoft.BizTalk.DefaultPipelines;
// ...
SendPipelineWrapper sendPipeline =
PipelineFactory.CreateEmptySendPipeline();
ReceivePipelineWrapper receivePipeline =
PipelineFactory.CreateReceivePipeline(typeof(XMLReceive));
Configuring Components
You can add components to an empty pipeline by instantiating the component class, setting its properties, and then adding it to the pipeline at the right stage.
Here’s an example of using the XML Disassembler component with the default options:
ReceivePipelineWrapper pipeline =
PipelineFactory.CreateEmptyReceivePipeline();
IBaseComponent component = new XmlDasmComp();
pipeline.AddComponent(component, PipelineStage.Disassemble);
The following example uses the MIME/SMIME Encoding component on a send pipeline:
SendPipelineWrapper pipeline =
PipelineFactory.CreateEmptySendPipeline();
MIME_SMIME_Encoder encoder = new MIME_SMIME_Encoder();
encoder.AddSigningCertToMessage = true;
encoder.ContentTransferEncoding =
MIME_SMIME_Encoder.MIMETransferEncodingType.Base64;
encoder.EnableEncryption = true;
pipeline.AddComponent(encoder, PipelineStage.Encode);
Configuring Known Schemas
If you want to use an assembler or disassembler on your pipeline, you’ll need to make sure that it can resolve the necessary schemas based on the fully qualified schema type, or the root element name (namespace#root). To accomplish this, you’ll need to make sure that the pipeline is aware of “known” document specifications before you execute them, so that the mock pipeline context can return the correct value when IPipelineContext.GetDocumentSpecByName() or IPipelineContext.GetDocumentSpecByType() is invoked by the assembler/disassembler component.
The library supports this through the AddDocSpec() method on the ReceivePipelineWrapper and SendPipelineWrapper classes. AddDocSpec() takes as an argument a Type handle referencing the strongly-typed, SchemaBase-derived class generated by the BizTalk project system when you compile an schema into a BizTalk Assembly. Here’s an example:
ReceivePipelineWrapper pipeline =
PipelineFactory.CreateEmptyReceivePipeline();
pipeline.AddDocSpec(typeof(Schema2_WPP));
AddDocSpec() will automatically handle multi-root schemas and make all roots in the schema known to the pipeline context, so you don’t have to worry about that. You can also add as many document specifications as needed, as long as there are no conflicts among them (i.e. don’t add two schemas with the conflicting namespace#root names).
Executing a Pipeline
Once you’ve configured a pipeline with the right components and schemas, you’ll want to execute it. For this you need to:
- Create the pipeline
- Create one or more input messages
- Execute the pipeline
- Examine the output messages
To create messages, you use the MessageHelper Class?.
Receive pipelines always take a single input message as input but might return zero or more output messages (like when debatching a message). Here’s a complete example or executing a receive pipeline:
ReceivePipelineWrapper pipeline =
PipelineFactory.CreateReceivePipeline(typeof(ReceivePipeline1));
// Create the input message to pass through the pipeline
Stream stream = DocLoader.LoadStream("SampleDocument.xml");
IBaseMessage inputMessage = MessageHelper.CreateFromStream(stream);
// Add the necessary schemas to the pipeline, so that
// disassembling works
pipeline.AddDocSpec(typeof(Schema1_NPP));
pipeline.AddDocSpec(typeof(Schema2_WPP));
// Execute the pipeline, and check the output
MessageCollection outputMessages = pipeline.Execute(inputMessage);
Send pipelines can take one or more input messages and will always return a single output message (most of the time only a single input message is provided, however). Here’s a complete example of executing a send pipeline with multiple inputs:
SendPipelineWrapper pipeline =
PipelineFactory.CreateSendPipeline(typeof(Env_SendPipeline));
// Create the input message to pass through the pipeline
string body =
@"<o:Body xmlns:o='http://SampleSchemas.SimpleBody'>
this is a body</o:Body>";
MessageCollection inputMessages = new MessageCollection();
inputMessages.Add(MessageHelper.CreateFromString(body));
inputMessages.Add(MessageHelper.CreateFromString(body));
inputMessages.Add(MessageHelper.CreateFromString(body));
// Add the necessary schemas to the pipeline, so that
// assembling works
pipeline.AddDocSpec(typeof(SimpleBody));
pipeline.AddDocSpec(typeof(SimpleEnv));
// Execute the pipeline, and check the output
// we get a single message batched with all the
// messages grouped into the envelope's body
IBaseMessage outputMessage = pipeline.Execute(inputMessages);







