Automated BizTalk Deployment

This post is deprecated, check this new post for improved scripts.

Introduction

At one of our customers, I set up a BizTalk environment with several applications, like applications for warehouse, subsidiary and customer interfaces. Some of these applications also use 2 separate servers, one in the internal network, and one in the DMZ network. These servers have completely different ports; for example. the DMZ server has ports connected to the outside world, which aren’t present on the internal server. Also, some applications are dependent on others, so deploying and undeploying has to be done in a specific order. To make this easy, I have set up a fully automatic BizTalk build and deployment setup. This is done by using PowerShell in combination with the BizTalk Deployment Framework. For my own reference, as well as for helping others set up an automated BizTalk deployment, I wrote this document. A basic understanding of BizTalk and PowerShell is needed to work with these examples. Special thanks go out to the blog of Randy Paulo.
Continue reading

Place root element in filename

To be able to see what type of message is in a file coming out of BizTalk, I created an encoding pipeline that includes the root element in the name of the file. Here is the execute method that I used.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/// <summary>
/// IComponent.Execute method is used to initiate the processing of the message in 
/// this pipeline component.
/// </summary>
/// <param name="pc">Pipeline context.</param>
/// <param name="inmsg">Input message.</param>
/// <returns>Original input message.</returns>
public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pc, 
    IBaseMessage pInMsg)
{
    // Create a new XML document
    XmlDocument xmlDocument = new XmlDocument();
 
    // Get the XML data from the message
    xmlDocument.Load(pInMsg.BodyPart.Data);
 
    // Set the filename, starting with the root element, and adding a GUID to make
    // sure the filename is unique
    string filename = String.Format("{0}-{1}.xml", 
        xmlDocument.DocumentElement.LocalName, Guid.NewGuid()).ToUpperInvariant();
 
    // To be able to use the filename in the BizTalk file adapter properties, we
    // promote ReceivedFileName
    // This gives us the %SourceFileName% parameter we can use as the filename for
    // the file adapter
    pInMsg.Context.Promote("ReceivedFileName", 
        "http://schemas.microsoft.com/BizTalk/2003/file-properties",
        navisionFilename);
 
    // Go back to the start of the message
    pInMsg.BodyPart.Data.Position = 0;
 
    // Continue processing the message
    return pInMsg;
}

Add Namespaces

At our customer, we are using several BizTalk solutions to seperate different BizTalk applications. For example, we have an own application for interfaces for the warehouse system, subsidiaries, suppliers, etc. We also have one application with shared resources like mappings and schemas. When receiving files from Navision, they don’t have a namespace, so we need to add this ourselves. We do this in the receive pipeline. Now to be able to use one pipeline to receive multiple types of messages, my collegue Rex van der Laan created a pipeline component that can add namespaces depending on the root element of the message. Here is the code that does this.
Continue reading

File Splitter

For one of the interfaces I was working on we get a flat file with information for multiple identifiers. We needed to split this file so that we only have 1 identifier per file. For this we create a new disassemble pipeline component. We will add 2 attributes to the class. The first is StartIndex, an integer which will define the location of a unique identifier in the file, for example a identifiercode. The second is Length, an integer that indicates how long the identifier is.
Continue reading