Monday, February 14, 2011

BizTalk Server 2009 Cumulative update package 1

The BizTalk 2009 team has released Cumulative update package 1. This includes all the hot-fixes for BizTalk 2009 till date

For information go to the following KB article click here

Monday, July 19, 2010

EDI Batching Automation

If you are trying to automate EDI Properties in BizTalk and struggling to find out how can you find out the status of a batch whether it's active. Here is the piece of code you may find quite useful.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Microsoft.Win32;
using System.Globalization;
using Microsoft.BizTalk.ExplorerOM;
using System.Xml;
using Microsoft.BizTalk.Edi.PartnerAgreementManager;

namespace PartyExport
{
    class Program
    {
        static void Main(string[] args)
        {
            ShowBatchesStatus();       
        }

      
        public static void ShowBatchesStatus()
        {
         
            using (BtsCatalogExplorer explorer = new BtsCatalogExplorer())
            {
                explorer.ConnectionString = BtsManagementDatabase.ConnectionString;
                foreach (Party party in explorer.Parties)
                {
                    Partner partner = new Partner(party.Name);
                    foreach (IPartnerBatch batch in partner.Batches.Batches)
                    {
                        Console.WriteLine(string.Format("Batch {0} Status is:{1}",batch.Name,batch.BatchingActivated?"Active":"Inactive"));     
                    }
                }
            }
    }

        internal class BtsManagementDatabase
        {
            private static string serverName;
            private static string databaseName;

            static BtsManagementDatabase()
            {
                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\BizTalk Server\3.0\Administration");
                serverName = (string)key.GetValue("MgmtDBServer");
                databaseName = (string)key.GetValue("MgmtDBName");
                key.Close();
            }

            public static string ServerName
            {
                get { return serverName; }
            }
            public static string DatabaseName
            {
                get { return databaseName; }
            }

            public static string ConnectionString
            {
                get
                {
                    string format = "Server={0};Database={1};Integrated Security=SSPI";
                    return string.Format(CultureInfo.CurrentCulture, format, new object[] { ServerName, DatabaseName });
                }

            }
        }
    }

          
}

Wednesday, June 16, 2010

Debugging BizTalk .NET Components using Visual Studio

Here are simple steps you can follow to debug any .NET code used by your BizTalk artifacts (helper code,pipeline components).

Step 1) Open the solution in Visual Studio and compile your solution in Debug mode.

Step 2) Identify the BizTalk HostInstance running your artifacts and start the host instance. For example, if you are trying to debug a pipeline components called by Receive Location then it's host configured in the receive location. However if you are trying to debug an external assembly called by Orchestration than use Host configured in that orchestration.

Step 3)  In Visual Studio select Tools-->Attach to Process--> Look for Host Instance named BTSNTSvc.exe (Tick Show process from all users) and select attach.

But what if your got multiple host configured on your machine they will all show up as BTSNTSvc.exe. In that case you need to find out the ProcessId of that host you identified in Step 2. Simply run the command from command prompt to find out the ProcessId

C:\>tasklist /svc

This will give the list of "Image Name","Process ID","Services". Search of your host name under the Services column and note down the processId. Switch back to Visual Studio Attach to Process dialog and select the host instance with matching processId and click Attach.

Step 4) Put a breakpoint the code and send a message through to BizTalk

Well done..you have just debugged your first BizTalk project.

Friday, May 28, 2010

Exporting a Specific Party from BizTalk Server 2009

Here is the small piece of code that can be use to Export specific party binding from BizTalk Server Management database. This works on BizTalk Server 2009 and should probably work on BizTalk Server 2006 R2

Here is the code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Microsoft.Win32;
using System.Globalization;
using Microsoft.BizTalk.ExplorerOM;
using System.Xml;

namespace PartyExport
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] parties = { "CompanyA", "CompanyD" };
            ExportSelectedPartiesToFile(parties, @"C:\Bindings.xml");
        }

        public static void ExportSelectedPartiesToFile(string[] parties, string exportPath)
        {
            
            BtsCatalogExplorer catalog = new BtsCatalogExplorer();
            catalog.ConnectionString = BtsManagementDatabase.ConnectionString;

            Microsoft.BizTalk.Deployment.Binding.BindingInfo bindingInfo = new Microsoft.BizTalk.Deployment.Binding.BindingInfo();

            using (SqlConnection sqlConnection = new SqlConnection(BtsManagementDatabase.ConnectionString))
            {
                Microsoft.BizTalk.Deployment.Binding.BindingParameters bindingParameters = new Microsoft.BizTalk.Deployment.Binding.BindingParameters(new Version());

                bindingInfo.PartyCollection = new Microsoft.BizTalk.Deployment.Binding.PartyCollection();
                Microsoft.BizTalk.Deployment.EdiParties ediParties = new Microsoft.BizTalk.Deployment.EdiParties();

                List<Party> lookupCollection = (from catalogParty in catalog.Parties.Cast<Party>()
                                                join lookupParty in parties on  catalogParty.Name equals lookupParty
                                                select catalogParty).ToList();

                foreach (Party party in lookupCollection)
                {
                    Microsoft.BizTalk.Deployment.IEdiParty ediParty = ediParties.GetParty(party.Name);
                    Microsoft.BizTalk.Deployment.Binding.Party bindingParty = new Microsoft.BizTalk.Deployment.Binding.Party();

                    bindingParty.Name = party.Name;
                    bindingParty.Aliases = new Microsoft.BizTalk.Deployment.Binding.PartyAliasCollection();

                    foreach (PartyAlias partyAlias in party.Aliases)
                    {
                        Microsoft.BizTalk.Deployment.Binding.PartyAlias bindingPartyAlias = new Microsoft.BizTalk.Deployment.Binding.PartyAlias();
                        bindingPartyAlias.IsAutoCreated = partyAlias.IsAutoCreated;
                        bindingPartyAlias.Name = partyAlias.Name;
                        bindingPartyAlias.Qualifier = partyAlias.Qualifier;
                        bindingPartyAlias.Value = partyAlias.Value;
                        bindingParty.Aliases.Add(bindingPartyAlias);
                    }
                    bindingParty.SendPorts = new Microsoft.BizTalk.Deployment.Binding.SendPortRefCollection();

                    foreach (SendPort sendPort in party.SendPorts)
                    {
                        Microsoft.BizTalk.Deployment.Binding.SendPortRef sendPortRef = new Microsoft.BizTalk.Deployment.Binding.SendPortRef();
                        sendPortRef.Name = sendPort.Name;
                        bindingParty.SendPorts.Add(sendPortRef);
                    }

                    if (party.SignatureCert != null)
                    {
                        bindingParty.SignatureCert = new Microsoft.BizTalk.Deployment.Binding.CertificateInfo();
                        bindingParty.SignatureCert.LongName = party.SignatureCert.LongName;
                        bindingParty.SignatureCert.ShortName = party.SignatureCert.ShortName;
                        bindingParty.SignatureCert.ThumbPrint = party.SignatureCert.ThumbPrint;
                    }
                    bindingParty.CustomData = party.CustomData;
                    if (ediParty != null)
                    {
                        string xml = ediParty.Xml;
                        bindingParty.EdiData = new XmlDocument();
                        bindingParty.EdiData.PreserveWhitespace = true;
                        bindingParty.EdiData.LoadXml(xml);
                    }

                    bindingInfo.PartyCollection.Add(bindingParty);
                }
                bindingInfo.SaveXml(exportPath);
            }
        }

        internal class BtsManagementDatabase
        {
            private static string serverName;
            private static string databaseName;

            static BtsManagementDatabase()
            {
                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\BizTalk Server\3.0\Administration");
                serverName = (string)key.GetValue("MgmtDBServer");
                databaseName = (string)key.GetValue("MgmtDBName");
                key.Close();
            }

            public static string ServerName
            {
                get { return serverName; }
            }
            public static string DatabaseName
            {
                get { return databaseName; }
            }

            public static string ConnectionString
            {
                get
                {
                    string format = "Server={0};Database={1};Integrated Security=SSPI";
                    return string.Format(CultureInfo.CurrentCulture, format, new object[] { ServerName, DatabaseName });
                }

            }
        }
    }

          
}