Monday 25 September 2017

End-To-End Tracking BizTalk Server Message Consumption Using Business Activity Monitoring (BAM)

This tutorial contains step by step guide how to do End-To-End tracking of message flow through receive port, send port and orchestrations using Continuation and BAM.

1.     To add the BAM add-in to Excel 2016

                    I.            In Excel 2016, click file ‘Options’ under file Menu.
                  II.            In the Excel Options dialog box, click Add-Ins.
                III.            In the Add-Ins pane, click Go.

                IV.            In the Add-Ins dialog box, select the Business Activity Monitoring check box, and then click OK.



2.     Defining a Business Activity

        I.            Open Microsoft Excel.

      II.            On the menu tool bar, click BAM Activity under BAM under the ‘Add-ins’ menu item.

a.      The Business Activity Monitoring Activity Wizard appears.

    III.            Click New Activity.

a.      The New Activity dialog box appears.

    IV.            Type a descriptive name for the activity in the Activity Name text box.

2.1 Creating new item

                    I.            Click New Item.

                  II.            In the New Activity Item dialog box, in the New Activity Item box, type a descriptive name for the activity item.

                III.            From the Item type drop-down menu, select a type for this item. Possible values include:


Item type
Description
Business Milestone
A date/time value. For example, an approval date for a purchase order.
Business Data – Text
A string containing any alphanumeric characters. For example, Ship to: City,
State/Province and Zip/Postal code.
Business Data – Integer
A whole number value. For example, the total number of purchases.
Business Data – Decimal
A decimal value. For example the total dollar amount of the PO.

If you select the item type "Business Data – Text", you must enter the maximum number of characters for the string in the Maximum length box.

                    I.            Repeat steps 1 through 3 to add as many items as needed to this activity.

                  II.            After you complete the Business Activity Monitoring Activity Wizard, the Business Activity Monitoring View Wizard starts automatically.

3.     Deploy the activity into BizTalk

                    I.            Open the excel sheet containing BAM Activity.

                  II.            On the menu tool bar, click export XML under BAM under the ‘Add-ins’ menu item.

                III.            Open the Command prompt and change the directory to BizTalk

a.      cd C:\Program Files (x86)\Microsoft BizTalk Server 2016\Tracking

b.      Prompt:

c.       bm deploy-all -DefinitionFile:D:\BAM\Activity.xml



Below two commands can be used to remove the activity or view.

bm remove-activity -Name:NaqabaConfirm

bm remove-view -Name:NaqabaConfirmV

4.     Generate Tracking profile

                                I.            Open the Tracking profile editor from start menu.

                              II.            Click on ‘Click here to import a BAM Activity Definition’ to select the activity we created above.

                            III.            Click on ‘Click here select an event source’, select the required orchestration from required solution/project.

                            IV.            Drag the items from orchestration to activity that we want to capture. For time related fields needs to drag and drop directly, on the other side if we want something from schema we need to right click on the Send/Receive and select ‘Message Payload schema’ and drag the required element.

                              V.            Click ‘apply Tracking profile’ under Tools menu.

                            VI.            Deploy the BizTalk Project/solution.

To open BAM portal in IE, it's must to enable the ‘compatibility mode’ in Internet Explorer by clicking Compatibility View settings under Tools menu.

Finally the activity we created looks like in BAM portal:


Tuesday 2 May 2017

How to Install and configure Certificates for BizTalk Server for sending digital signed messages

Note: I tried to capture and write down basic steps in order to make this post more simple so that one cannot get confused.


My scenario is to consume the Web Service by using ‘Static Solicit-Response Send Port’ with SOAP adapter. I  think this can be applicable to other send and receive ports as well.

Problem:

I tried several blogs and videos to fix my issue. The main issue I faced is I got confused which certificate store is used for which certificate for private and public both.

Company AA needs to consume company BB’s web service with digital signature.

Company BB shared their Public SSL Certificate (Public key) and asked to send all the message with digital signature otherwise they will not accept any request.

Solution:
1.       As per scenario Company AA needs to Request a private-public key pair for digital signatures from the certification authority (CA), Below steps are shown with images.

Note: There are several other ways to create the Private key

1.1 Press simultaneously the Windows and R keys on your keyboard and type MMC and hit enter key.


1.2 From File Menu click ‘Add/Remove Snap-ins’ Scroll down and click on ‘Certificates’ then click ‘Add >’

1.3 On ‘Certificate Snap-in’ window choose ’Computer account’ then click ‘Next’ then click ‘finish’.



1.4 Repeat the above step keep ‘Certificates’ selected on ‘Add/Remove Snap-in’ window and click ‘Add’ button.

1.5 On ‘Certificate Snap-in’ window choose ’My User account’ then ‘finish’ button.


2.       Go to certificate store named ‘Personal Certificates’ right click on it and under ‘All Tasks’ click ‘Request New certificate’




2.1 Click Next Button as shown in below image.



2.2 Do not do anything just click Next button as shown in below image.


2.3 Check the check box next to ‘Computer’ and click ‘Enroll’ button:


2.4 Click Finish button:



3.       Once Private key is ready we have to obtain the public key pair of it.

3.1 Right click on the newly created ‘Private Certificate’ click ‘All Tasks’ then ‘Export’


              3.2 on ‘Certificate Export Wizard’ click Next.


          3.3 Again Click Next:



        3.4 Again click Next



       3.5   Click Browse, type any name and Then click Save



4.       Share the Public certificate (Public key ) created in above(Step 3) with client, in our case it is Company BB.

              4.1 BB will import AA’s public key in appropriate store.
              4.2 BB will share their Public Key with AA.

5.       We have to Import our public key(AA’s Key)  and BB’s Key on stores as shown below:


Local Computer
Current User
Personal
AA's Public Key
BB's Public Key, AA's Public Key
Trusted Root Certification Authorities
AA's Public Key

Trusted People

BB's Public Key
Other People
AA's Public Key



Note: Below Commands can also be used to import the certificates.

a)       CertWizard /Publickey "C:\Users\bz_admin\Desktop\Certificate\xxxxxx.cer"
b)      CertWizard /Privatekey "C:\Users\bz_admin\Desktop\Certificate\xxxxx.pfx"


6.       Now it’s time to setup Certificate on BizTalk Server.
6.1 On BizTalk Administration console Right Click on the ‘BizTalk Server Group’ and click ‘Properties’


6.2 Click on Certificate tab and then click ‘Browse’ button:


6.3 Choose the appropriate certificate, Certificates ‘Common name’ and ‘ThumbPrint’ will be populated automatically.



7.       Now go to the port and configure it(for my case it’s SOAP Send Port ), On general Tab click ‘Configure’ on General tab paste ‘Client Certificate Thumbprint’ then click OK, then Apply and at last ‘OK’.

Restart the  host instance and all done.

Friday 9 October 2015

Enabling BizTalk Receive locations using PowerShell script

Problem:
Currently I am working on BizTalk 2013 project after development and deployment I am responsible to administrator the BizTalk Production environment. Often some receive locations go down and processing of urgent messages stopped processing, Here is need of something that brings the ports(s) up.

Solution:
PowerShell can solve the above issue. If we use PowerShell script it will check the status of specific receive location either it is enable or disable. If the receive location is already enable do nothing but if the receive location is disabled, I want the status of disabled receive location through email and restart the host to which that receive location is associated and enable the receive location. After successful enabling of receive location receive successful email.

Configure PowerShell

1.      Open “windows PowerShell” ‘with run as administrator’

2.      Type the command “Set-ExecutionPolicy Unrestricted” and hit enter.

PowerShell Script:
We will need to open PowerShell IDE for the development of PowerShell scripts.

1.      To open the PowerShell IDE go to Start => All Programs => Accessoires => Windows PowerShell -> windows PowerShell ISE.

2.      BizTalk.ExplorerOM and WMI will used to communicate to the BizTalk environment.

3.      There is need of functions to manage what we want, i.e. checking the status of receive location, sending status of receive location, restarting host instance and enabling the receive location:
 
# Import external assembly and create a new object
[void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.ExplorerOM")
$Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
#BizTalk Config
$Catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"  #connectionstring to the mgmt db
$hostname = "BizTalkServerApplication" #hostname for the JMS host
$rcvLocation = "GetNewConfirmReceiveLocation" #receive location
#Email Config
$emailFrom = "Bz_admin@XXXX.com.sa"
$emailTo = "mmasood@XXXX.com.sa"
$emailSubject  = "Receive Location 'GetNewConfirmReceiveLocation' -Service: 8 on BIZTALK PROD is DOWN"
$emailSubject2 = "Receive Location 'GetNewConfirmReceiveLocation' -Service: 8 BIZTALK PROD is UP"
$emailServer ="Mail.XXXX.com.sa"
#Function to retrieve the status of the specific receive location
function getStatus(){
foreach ($receivePort in $catalog.ReceivePorts)
   {
       foreach($receiveLoc in $receivePort.ReceiveLocations  | Where {$_.Name -eq $rcvLocation}){
            return $receiveLoc.Enable
       }
   }
}
#Function to enable the receive location
function enableReceiveLocation(){
     #$location.Enable()
        $recvloc = get-wmiobject MSBTS_ReceiveLocation `
       -namespace 'root\MicrosoftBizTalkServer' `
       -filter "Name='GetNewConfirmReceiveLocation'"
       [void]$recvloc.Enable()
       [void]$Catalog.Refresh()
   }
#Function to sends an error email
function sendEmail(){
$message = "GetNewConfirmReceiveLocation is Down. Trying to restart the host and enabling the receive location"
    $smtp=new-object Net.Mail.SmtpClient($emailServer)
    $smtp.Send($emailFrom, $emailTo, $emailSubject, $message)
 }
#Function to sends an ok email
function sendEmailok(){
$messagee = "GetNewConfirmReceiveLocation is brought up successfully"
$smtp=new-object Net.Mail.SmtpClient($emailServer)
$smtp.Send($emailFrom, $emailTo, $emailSubject2, $messagee)
}
$keeplooping = $true
$isok = $false
$i = 0;
#check status 5 times
$isEnabled = getStatus
if($isEnabled -eq $false){
while($keeplooping -eq $true){
$isEnabled = getStatus
if($isEnabled -eq $false){
sendEmail
#Restart host
Restart-Service -Displayname "BizTalk Service BizTalk Group : ${hostname}"
#wait a few seconds
Start-Sleep -s 30 
#Enable receive location
enableReceiveLocation
#Wait 5 minutes
Start-Sleep -s 30
$i++;
        if($i -gt 4){
            $keeplooping = $false
        }
    }else{
        sendEmailok
        $keeplooping = $false
        $isok = $true
    }
}
}
This PowerShell script will check the status of a receive location if receive location is already enabled script will do nothing. If the receive location is disabled then script will first send an error email stating receive location is down\disabled then tries 3 attempts to restart the host instance and enabling the receive location. Once host instance restarted successfully and port enabled successfully it will again send a successfully email stating the receive location XXXXXXXXX is enabled successfully.
After testing and verification of above script then we may put this under windows scheduler. OR put the code in SQL Agent.