本主題中的程式代碼說明如何快速部署及啟動新版本的協調流程。 因為手動作業可能需要幾秒鐘的時間才能執行,所以手動取消登錄協調流程,然後啟動新版本的作業可能會導致暫停或重複的訊息。 本主題中說明的程序設計方法可讓您更快速地執行這些作業–減少暫停和重複訊息的可能性,以及做為單一交易,因此,如果一個作業失敗,這兩個協調流程會保持與開頭相同的狀態。
備註
在罕見的情況下,當您以新版本更新的協調流程在高負載下運作時,即使您以程序設計方式取消登記並登記協調流程,某些訊息仍可能會暫停。 建議您在執行這些作業之後,檢查已暫停的訊息佇列並繼續任何暫停的訊息。
下列程式代碼範例說明如何使用 Explorer 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;
}
}
}