BizTalk Bindings Exportation: How to Export BizTalk Server Bindings by a List of Port Names with PowerShell

Finally, the last blog post on this series about BizTalk Bindings Exportation with PowerShell:

  • How can we easily export a binding file from a BizTalk Application?
  • How can we easily export a binding file from a specify assembly?
    • Using the fully qualified name (FQName) of the assembly.
    • Using only the assembly name
  • How can we easily export a binding file from a Receive Port?
  • How can we easily export a binding file from a Send Port?
  • How can we easily export a binding file from a list of assemblies?
    • By fully qualified name (FQName);
    • By assembly names;

Today’s blog post will be about: How to Export BizTalk Server Bindings by a List of Port Names with PowerShell.

In other words, instead of generating a specific binding file for each port: Receive Port and/or Send Port, we will include all of the receive ports and send ports bindings in a unique binding file, so it can easily be handled.

This functionality should be something that should exist in the BizTalk Server Administration Console, but it is impossible to be addressed using the out-of-the-box tool BizTalk Server Administration Console or even with the BTSTask command-line tool which is included with BizTalk Server.

As always, and like the previous samples, we could fully automate this Binding generation for each environment, but once again let’s keep it simple. With this PowerShell sample, we will be able to generate a unique binding file for a list of specific assemblies deployed in my BizTalk Server environment. The script will perform the following tasks:

  • Generate a Binding file for 3 environments DEV, QA and PRD
  • Generate a unique binding file, instead of having separated binding files for each Port name (receive port and/or send port)
function bts-list-ports-exportbindings([string]$bindingFilePath, [string]$bindingNamePrefix, [string]$appName, [string]$rcvPortNames, [string]$sndPortNames, [boolean]$generateDiffEnvBindings)
{
    $finalBinding = (Get-Content "C:TempBTSTemplateBindingInfo.xml")
    $moduleRefNode = $finalBinding.SelectSingleNode("BindingInfo/ModuleRefCollection")
    $sendPortNode = $finalBinding.SelectSingleNode("BindingInfo/SendPortCollection")
    $receivePortNode = $finalBinding.SelectSingleNode("BindingInfo/ReceivePortCollection")

    $listRcvPorts = $rcvPortNames.Split("|")
    $listSndPorts = $sndPortNames.Split("|")

    $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.BindingInfo.xml /ApplicationName:$appName ”
    Start-Process "BTSTask.exe" $taskParams -Wait

    $xml = (Get-Content "$bindingfilePath$appName.BindingInfo.xml")

    foreach($receivePortBinding in $xml.BindingInfo.ReceivePortCollection.ReceivePort)
    {
        if($listRcvPorts -Contains $receivePortBinding.Name)
        {
            $node = $finalBinding.ImportNode(($receivePortBinding), $true);
            $receivePortNode.AppendChild($node);
        }
    }

    foreach($sendPortBinding in $xml.BindingInfo.SendPortCollection.SendPort)
    {
        if($listSndPorts -Contains $sendPortBinding.Name)
        {
            $node = $finalBinding.ImportNode(($sendPortBinding), $true);
            $sendPortNode.AppendChild($node);
        }
    }

    $finalBinding.Save("$bindingfilePath$bindingNamePrefix.BindingInfo.xml")

    if($generateDiffEnvBindings)
    {
        $finalBinding.Save("$bindingfilePath$bindingNamePrefix.QA.BindingInfo.xml")
        $finalBinding.Save("$bindingfilePath$bindingNamePrefix.PRD.BindingInfo.xml")
    }
}

THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.

We will not change the URI for each environment – it could be done, but is not the goal here, it is just a start.

You can download the full script from here: Export BizTalk Server Bindings from a List of Port Names with PowerShell

The post BizTalk Bindings Exportation: How to Export BizTalk Server Bindings by a List of Port Names with PowerShell appeared first on BizTalk360.

BizTalk Bindings Exportation: How to Export BizTalk Server Send Port Binding with PowerShell

Let’s continue with some deep dive scripts about exporting BizTalk Server bindings, addressing some useful and unsupported scenarios that are impossible to be addressed using out-of-the-box with the standard tools BizTalk Server Administration Console or even with the BTSTask command-line tool included with BizTalk Server.

  • How can we easily export a binding file from a list of assemblies?
  • How can we easily export a binding file from a Receive Port?
  • How can we easily export a binding file from a Send Port?
  • And many more

Also recapitulating some of the default scenarios/functionalities already addressed previously done in a different way and with small improvements with PowerShell:

  • How can we easily export a binding file from a BizTalk Application?
  • How can we easily export a binding file from a specify assembly?
    • Using the fully qualified name (FQName) of the assembly.
    • Using only the assembly name

Today’s blog post will be about: How to Export BizTalk Server Send Port Binding with PowerShell.

Like Receive Ports, this functionality should be something that should exist in the BizTalk Server Administration Console, but it doesn’t. In some cases we can achieve this in the developing phase using the Visual Studio, while we generate the schemas for LOB systems, for example:

  • In the Solution Explorer, right-click a BizTalk project, point to Add, and then click Add Generated Items
  • In the Add Generated Items… – <BizTalk ProjectName> dialog box, in the Templates section, click Consume Adapter Service and then click Add
  • You should then select the binding you want to use, configure the parameters and the operations you want to do

Along with the LOB Schemas, this will also generate the binding files for the receive port or send port.

So, again, the question that we may ask is: Is there any way that we can easily accomplish this? The response is yes, again, all of this can be fully automated using, for example, PowerShell scripts.

This script, combined with the Receive Ports, is extremely useful if:

  • you use several cases of content-based routing (without orchestrations)
  • you create new send ports, for example with filters
  • new receive port in your environment

and if you don’t want to export/import the full application binding that may affect something that you already have in production.

Like the previous samples, we could fully automate this Binding generation for each environment, but once again, let’s keep it simple and address what is mandatory and easily forgotten. With this PowerShell sample we will be able to generate a binding file for a specific assembly name deployed in my BizTalk Server environment. The script will perform the following tasks:

  • Generate a Binding file for 3 environments DEV, QA and PRD
  • Changing the NT Group Name for each different environment
  • Generate a specific Send Port deployed in your environment
function bts-send-port-exportbindings([string]$bindingFilePath, [string]$appName, [string]$portName, [boolean]$generateDiffEnvBindings)
{
    $portRen = $portName.Replace(" ", "")
    $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.$portRen.BindingInfo.xml /ApplicationName:$appName ”
    #First version: $p = [diagnostics.process]::start(“BTSTask.exe”, $taskParams)
    Start-Process "BTSTask.exe" $taskParams -Wait

    $xml = (Get-Content "$bindingfilePath$appName.$portRen.BindingInfo.xml")
    foreach($RemoveModuleRef in $xml.BindingInfo.ModuleRefCollection.ModuleRef)
    {
        $xml.BindingInfo.ModuleRefCollection.RemoveChild($RemoveModuleRef)
    }
    foreach($RemoveSendPort in $xml.BindingInfo.SendPortCollection.SendPort)
    {
        if($RemoveSendPort.Name -ne $portName)
        {
            $xml.BindingInfo.SendPortCollection.RemoveChild($RemoveSendPort)
        }
    }
    foreach($RemoveReceivePort in $xml.BindingInfo.ReceivePortCollection.ReceivePort)
    {
        $xml.BindingInfo.ReceivePortCollection.RemoveChild($RemoveReceivePort)
    }
    $xml.Save("$bindingfilePath$appName.$portRen.BindingInfo.xml")

    if($generateDiffEnvBindings)
    {
        # QA Binding Info Generation
        $xml.SelectNodes("//Host") | % { 
            $_.NtGroupName = $global:qaNTGroupName
        }
        $xml.Save("$bindingfilePath$appName.$portRen.QA.BindingInfo.xml")

        # PRD Binding Info Generation
        $xml.SelectNodes("//Host") | % { 
            $_.NtGroupName = $global:prdNTGroupName
        }
        $xml.Save("$bindingfilePath$appName.$portRen.PRD.BindingInfo.xml")
    }
}

THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.

You can download the full script from here: Export BizTalk Server Send Port Binding with PowerShell

The post BizTalk Bindings Exportation: How to Export BizTalk Server Send Port Binding with PowerShell appeared first on BizTalk360.

Working With Start Orchestration Shapes, Self Correlated Ports, and Configured Port Parameters

These three topics could be entire blog posts on there own.  In this case, I’ll briefly cover all three and show how to use them all together.



Start Orchestration – This shape give you the ability to asynchronously start a new Orchestration.  You can pass in all types of parameters but you can not return parameters like the Call Orchestration Shape. 



Passing Configured Port Parameters – This is an input parameter type for Call and Start Orchestrations.  This can be used to pass in already configured ports to use to send messages back into the original Orchestration. 



Direct Binding using Self Correlation – When passing Self Correlation ports to a Started Orchestration a unique token is placed in BTS.PartnerService.  This is used for the return subscription.  I have not worked with Self Correlation Ports in any other scenario although they can be used on there own without a Start or Called Orchestration.



Solution Overview:  A single message is received into a Master Orchestration (Master).  This single message is then used to Start two different Orchestrations (SharedLogicA and SharedLogicB).  Inside these two Orchestrations, the message is “processed” (i.e. mapped and a 5 to 15 second delay is used to simulate processing).  The resulting mapped messages are returned to the Master Orchestration.  A single result message is sent out.



Download: Passing Configured Port Parameters Sample



The master Orchestration looks something like this:





How does this differ from Direct Binding Using Partner Ports? 


It is very similar except that you do not use the Start Orchestration shape (thus can not pass parameters, multiple messages, and so on).  Using Partner Ports, if you wanted a message back you would need to create a Correction Set and work out all those complexities.  There is some other under the cover differences between the two but that is for another post.



How to set this up on your own:


Step 1: Create the Master Orchestration with a Receive Port and a SharedLogic Orchestration.  Set up all required input and output messages.  Set up the Send Shape inside the SharedLogic Orchestation to send back the correct message.



Step 2: Inside the Master Orchestration add the Receive Shape and set it up to receive the response message from the SharedLogic Orchestration.  Select the Red ! to configure the Operation for the Receive Shape.  Give the Port a name (Port_A), create a new port type (PortType_A), select Directing Binding – Self Correlation.





Step 3: Inside the SharedLogic Orchestration add the parameters that will be passed in by from the Master.  In this case, an input message (InputA) and a configured port parameter (Port_1).  For the port type, select the type create above (PortType_A), for Port Binding select “I’ll always be sending messages on this port”.  Connect your Send Shape to your new Port. 









Step 4: Lastly, inside your Master Orchestration add a Start Orchestration Shape.  Select your Sharedlogic Orchestration.  Set your two input parameters if needed.







Note that you can send and receive messages on the same port type when using the Start Orchestration Shape.  If you tried this same approach with the Call Orchestration shape you would get a build error.  Read more about this on Charles Young awesome article on this topic.