以编程方式部署和启动业务流程的新版本

本主题中的代码说明如何快速部署和启动新版本的业务流程。 由于手动操作会花几秒钟来执行,因此手动取消登记业务流程并随后启动新版本的业务流程将导致生成挂起或重复的消息。 通过本主题中说明的编程方法,可以更快速地执行这些操作,从而减小生成挂起和重复消息的可能性;并且可作为单个事务来执行这些操作,以便其中一个操作失败时,这两个业务流程都保持开始时的相同状态。

注意

在极少数情况下,当使用新版本更新的业务流程在高负载下运行时,即使以编程方式取消登记并登记业务流程,某些消息也会挂起。 建议在执行这些操作后,检查挂起的消息队列并恢复任何挂起的消息。

下面的代码示例说明如何使用浏览器 OM API 取消登记现有的业务流程并启动新版本的业务流程。

using System;  
using Microsoft.BizTalk.ExplorerOM;  
#endregion  
namespace OrchestrationBinding  
{  
class OrchestrationBinding  
{  
static void Main(string[] args)  
{  
            UpdateOrchestration();  
}  
        static public void UpdateOrchestration()  
        {  
            // Create the root object and set the connection string  
            BtsCatalogExplorer catalog = new BtsCatalogExplorer();  
            catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";  
            string orchestrationAssemblyV1 = "HelloWorld, Version=1.0.0.0, Culture=neutral, PublicKeyToken=99561c477e487f14";  
            string orchestrationAssemblyV2 = "HelloWorld, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99561c477e487f14";  
            string orchestrationName = "Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule";  
            try  
            {  
                BtsAssembly assemblyV1 = FindAssemblyByFullName(catalog.Assemblies, orchestrationAssemblyV1);  
                BtsAssembly assemblyV2 = FindAssemblyByFullName(catalog.Assemblies, orchestrationAssemblyV2);  
                BtsOrchestration orchestrationV1 = assemblyV1.Orchestrations[orchestrationName];  
                BtsOrchestration orchestrationV2 = assemblyV2.Orchestrations[orchestrationName];  
                orchestrationV1.Status = OrchestrationStatus.Unenlisted;  
                orchestrationV2.Status = OrchestrationStatus.Started;  
                // Commit the accumulated changes transactionally  
                catalog.SaveChanges();  
            }  
            catch (Exception e)  
            {  
                catalog.DiscardChanges();  
                throw;  
            }  
        }  
        static BtsAssembly FindAssemblyByFullName(BtsAssemblyCollection assemblies, string fullName)  
        {  
            foreach (BtsAssembly assembly in assemblies)  
            {  
                if (assembly.DisplayName == fullName)  
                    return assembly;  
            }  
            return null;  
        }  
}  
}  

另请参阅

更新 BizTalk 应用程序
如何登记业务流程
如何取消登记业务流程