このトピックのコードでは、オーケストレーションの新しいバージョンをすばやくデプロイして開始する方法を示します。 手動操作の実行には数秒かかる場合があるため、手動でオーケストレーションの登録を解除してから新しいバージョンを開始すると、メッセージが中断または重複する可能性があります。 このトピックで示すプログラムによる方法を使用すると、これらの操作をより迅速に実行できます。中断されたメッセージや重複するメッセージの可能性を減らし、1 つのトランザクションとして実行できるため、1 つの操作が失敗した場合、両方のオーケストレーションは最初と同じ状態に残ります。
注
まれに、新しいバージョンで更新するオーケストレーションが高負荷で動作している場合、オーケストレーションをプログラムで登録解除して参加した場合でも、一部のメッセージが中断されることがあります。 これらの操作を実行した後、中断されたメッセージ キューを確認し、中断されたメッセージを再開することをお勧めします。
次のコード サンプルは、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;
}
}
}