PartnerManagement (BizTalk Server サンプル)
PartnerManagement サンプルは、ExplorerOM 管理オブジェクトを使用してBizTalk Server環境でパーティを管理する方法を示しています。
前提条件
このサンプルの管理オブジェクトを使用するには、BizTalk Server管理特権が必要です。
Windows PowerShell スクリプトを実行するには、Windows PowerShell 実行ポリシーが必要です。 詳細については、「 実行ポリシーの確認」を参照してください。
このサンプルの処理
このサンプルでは、 Microsoft.BizTalk.ExplorerOM 名前空間の管理クラスを使用してパーティを管理する方法を示します。 パーティは、ビジネス プロセスで操作できる取引先またはバックエンド アプリケーションを表します。 パーティ全般の詳細については、 パーティ または ロール リンクとサービス リンク ロールに関するドキュメントを参照してください。 このサンプルは、Microsoft Visual C# で記述されています。 このトピックには、Windows PowerShell のスクリプト例も含まれています。 このサンプルは次の操作を示します。
カスタムエイリアスまたは標準エイリアスを使用して新しいパーティを作成し、既存のBizTalk Serverを追加してパーティにポートを送信します。
既存のロール リンクを持つ新しいパーティを BizTalk Server に参加させる。
新しいパーティを参加解除する。
新しいパーティを削除する。
このサンプルの場所
このサンプルは、SDK がある次の場所にあります。
<サンプル パス>\管理\ExplorerOM\PartnerManagement
次の表は、このサンプルのファイルとその目的を示しています。
ファイル | 説明 |
---|---|
PartnerManagement.cs | このサンプルで示す操作用の Visual C# ソース ファイル。 |
PartnerManagement.sln と PartnerManagement.csproj | このサンプルのソリューション ファイルとプロジェクト ファイル。 |
このサンプルのビルドおよび実行
サンプルをビルドする前に、コードを 4 か所で変更し、BizTalk Server のサンプルをカスタマイズする必要があります。 これは、サンプルではパーティに関連付けられた送信ポートと参加のロールに任意の名前を使用しているためです。 したがって、サンプルに有効な名前を指定する必要があります。 このサンプルを示すために、このトピックでは、最初にディレクトリから PartyResolution サンプルをビルドする方法について説明します: <Samples Path>\Orchestrations\PartyResolution。 この方法を使用するのは、有効なロール名と送信ポート名が BizTalk Server に存在することを確認し、サンプルの手順を示すことができるようにするためです。
このサンプルをビルドするには
最初に、有効なロール名と送信ポート名をサンプルで使用できるよう、PartyResolution サンプルがビルドされ初期化されていることを確認します。 これは、PartyResolution (BizTalk Server Sample) の「このサンプルのビルドと初期化」というタイトルのセクションに記載されています。
Visual Studio で、ソリューション ファイル PartnerManagement.sln を開きます。
ソリューション エクスプローラーでソース ファイル PartnerManagement.cs を開きます。
CreateParty という名前の関数まで下にスクロールし、PartyResolution サンプルから 2 つの送信ポート名を挿入するか、BizTalk サーバー環境の有効な名前を使用します。 次のコード例では、PartyResolution サンプルの送信ポートを使用する変更を示しています。
// Replacing arbitrary send port names with PartyResolution send port names === // myParty.SendPorts.Add(catalog.SendPorts["NormalDelivery"]); // myParty.SendPorts.Add(catalog.SendPorts["ExpressDelivery"]); myParty.SendPorts.Add(catalog.SendPorts["SP_FilesToShipmentAgency1"]); myParty.SendPorts.Add(catalog.SendPorts["SP_FilesToShipmentAgency2"]);
EnlistParty という名前の関数まで下にスクロールし、foreach ループを変更して、参加リストで使用する "ShipmentRole" という名前のロールが Supplier アセンブリで検索されるようにします。 次のコード例では、PartyResolution サンプルの ShipmentRole を使用する変更を示しています。
// Search for the “Shipmentrole” instead of “shipperRole” Role svcRole = null; //=== foreach (Role role in catalog.Assemblies[0].Roles) foreach (Role role in catalog.Assemblies["Supplier"].Roles) { //=== if (role.Name == "ShipperRole") if (role.Name == "ShipmentRole") { svcRole = role; break; } }
UnenlistParty という名前の関数まで下にスクロールし、foreach ループを変更して、Supplier アセンブリで ShipmentRole を検索します。 次のコード例に、この変更を示します。
// Search for the “ShipmentRole” instead of “shipperRole” Role svcRole = null; //=== foreach (Role role in catalog.Assemblies[0].Roles) foreach (Role role in catalog.Assemblies["Supplier"].Roles) { //=== if (role.Name == "ShipperRole") if (role.Name == "ShipmentRole") { svcRole = role; break; } }
ShipmentRole を持つ新しいパーティを作成し、参加させた後、サンプルはすぐにパーティを参加解除し削除するようデザインされています。 メイン プロシージャに次のコード変更を追加して実行を一時停止し、BizTalk Server管理コンソールで新しいパーティの作成された参加リストを表示できるようにします。
static void Main(string[] args) { CreateParty(); EnlistParty(); Console.WriteLine("\nNew Party created and enlisted.\n\nPress <Enter> to unenlist and delete.\n"); Console.ReadLine(); UnenlistParty(); DeleteParty(); }
[ビルド] メニューの [ソリューションのビルド] をクリックします。
このサンプルを実行するには
コマンド ウィンドウを開き、次のフォルダーに移動します。
<サンプル パス>\管理\ExplorerOM\PartnerManagement\bin\Debug
PartnerManagement.exe ファイルを実行します。
このサンプルでは、新しいパーティが作成されて参加したというメッセージが表示されたら、BizTalk Server管理コンソールを開き、[パーティ] ノードの下に FedEx という名前の新しいパーティを表示します。
BizTalk Server管理コンソールで、ツリー ビューの [Applications\BizTalk Application 1\Role Links] の下にある ShipmentRole に移動します。 [ShipmentRole] をダブルクリックし、SupplierAdvice 操作にマップされた ShipmentAgency1 と、参加リストの SupplierOrder 操作にマップされた ShipmentAgency2 に注目します。
コマンド ウィンドウで Enter キーを押すと、サンプルを参加解除し削除できます。
BizTalk Server管理コンソールで、パーティが ShipmentRole から参加解除され、[パーティ] ノードから削除されたことを確認します。
Windows PowerShell スクリプトの例
次のWindows PowerShellスクリプトの例は、ExplorerOM クラスの同じ機能を示すために使用できます。
#===============================================================#
#=== ===#
#=== Create a new party named "FedEx" as an example. ===#
#=== ===#
#=== Two Shipment agency send ports from the PartyResolution ===#
#=== sample will be added to the party. ===#
#=== ===#
#===============================================================#
Function CreateParty
{
#=== Create a party =====================#
$myParty = $Catalog.AddNewParty()
$myParty.Name = "FedEx"
#=== create a standard alias ==========================#
$standardAlias = $myParty.AddNewAlias()
$standardAlias.Name = "D-U-N-S (Dun & Bradstreet)"
$standardAlias.Value = "Value1"
#=== Create a custom alias ==================#
$customAlias = $myParty.AddNewAlias()
$customAlias.Name = "Telephone"
$customAlias.Qualifier = "100"
$customAlias.Value = "4255550234"
#=== Add party send ports =====================================================#
#===============================================================#
#=== Have to use IList directly on this sendports collection ===#
#=== to work around a PowerShell issue. ===#
#===============================================================#
$iList = [System.Collections.IList]
$sendport1 = $Catalog.SendPorts["SP_FilesToShipmentAgency1"]
[void] $iList.GetMethod("Add").Invoke($myParty.SendPorts,$sendport1)
$sendport2 = $Catalog.SendPorts["SP_FilesToShipmentAgency2"]
[void] $iList.GetMethod("Add").Invoke($myParty.SendPorts,$sendport2)
#=== Specify a signature certificate, make sure the certificate is available ===#
#=== in the AddressBook store of the Local Machine ===#
foreach ($certificate in $Catalog.Certificates)
{
if ($certificate.ShortName -eq "BR, Certisign Certificadora Digital Ltda., Certisign - Autoridade Certificadora - AC2")
{
$myParty.SignatureCert = $certificate
}
}
#=== Commit the changes ===#
$catalog.SaveChanges()
}
#===============================================================#
#=== ===#
#=== Delete the party named "FedEx" ===#
#=== ===#
#===============================================================#
Function DeleteParty
{
$Catalog.RemoveParty($Catalog.Parties["FedEx"])
#=== Commit the changes ===#
$catalog.SaveChanges()
}
#===============================================================#
#=== ===#
#=== Enlist the "FedEx" party with the "ShipmentRole" ===#
#=== ===#
#===============================================================#
Function EnlistParty
{
$myParty = $Catalog.Parties["FedEx"]
#=== Get the "ShipmentRole" in the Supplier assembly. ===#
$svcRole = $Catalog.Assemblies["Supplier"].Roles["ShipmentRole"]
#=== Enlist the party under the shipper role ===#
$enlistedParty = $svcRole.AddNewEnlistedParty($myParty)
#===============================================================#
#=== Have to use IList directly on this sendports collection ===#
#=== to work around a PowerShell issue. ===#
#===============================================================#
$iList = [System.Collections.IList]
#===============================================================#
#=== Example port to be used for the role's "SupplierAdvice" ===#
#=== operation. ===#
#=== Using the first send port added to the new party which ===#
#=== is "SP_FilesToShipmentAgency1" at index 0 in the ===#
#=== sendports collection. ===#
#===============================================================#
$enlistedParty.Mappings[0].SendPort = $iList.GetProperty("Item").GetValue($myParty.SendPorts,0)
#===============================================================#
#=== Example port to be used for the role's "SupplierOrder" ===#
#=== operation. ===#
#=== Using the second send port added to the new party which ===#
#=== is "SP_FilesToShipmentAgency2" at index 1 in the ===#
#=== sendports collection. ===#
#===============================================================#
$enlistedParty.Mappings[1].SendPort = $iList.GetProperty("Item").GetValue($myParty.SendPorts,1)
#=== Commit the changes ===#
$Catalog.SaveChanges()
}
#===============================================================#
#=== ===#
#=== Unenlist the "FedEx" party from the ShipmentRole ===#
#=== ===#
#===============================================================#
Function UnenlistParty
{
#=== Get the "ShipmentRole" from the Supplier assembly. ===#
$svcRole = $Catalog.Assemblies["Supplier"].Roles["ShipmentRole"]
#=== Remove the "FedEx" party ===#
foreach ($enlistedparty in $svcRole.EnlistedParties)
{
if ($enlistedparty.Party.Name -eq "FedEx")
{
$svcRole.RemoveEnlistedParty($enlistedparty)
break
}
}
#=== Commit the changes ===#
$Catalog.SaveChanges()
}
#===================#
#=== Main Script ===#
#===================#
#=== Make sure the ExplorerOM assembly is loaded ===#
[void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.ExplorerOM")
#=== Connect to the BizTalk Management database ===#
$Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
$Catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"
#=== This sample expects the PartyResolution sample to be built and deployed ===#
#=== to the BizTalk Server. ===#
write-host `r`nMake sure the "PartyResolution" sample application from the Orchestrations
write-host sample directory is deployed and running.
write-host By default it will be listed in the BizTalk Server Administration Console
write-host with the application name: `"BizTalk.Application.1`"`r`n
$SupplierAssembly = $Catalog.Assemblies["Supplier"]
#==================================================================#
#=== Register a trap handler to discard changes on exceptions ===#
#=== Execution will continue in the event we want to unenlist, ===#
#=== and delete the party. ===#
#==================================================================#
$Script:NoExceptionOccurred = $true
$ErrorActionPreference="silentlycontinue"
trap
{
$Script:NoExceptionOccurred = $false
"Exception encountered:`r`n"; $_; "`r`nDiscarding Changes and continuing execution so we can attempt to clean up the party...`r`n"
$Catalog.DiscardChanges()
}
CreateParty
EnlistParty
if ($Script:NoExceptionOccurred)
{
Write-Host "`r`nExample Party `"FedEx`" should be created and enlisted with the `"ShipmentRole`".`r`n"
Write-Host You can view the results in the BizTalk Server Administration console.`r`n
Write-Host "Press <Enter> to unenlist and delete...`r`n"
Read-Host
}
UnenlistParty
DeleteParty
次に、PowerShell スクリプト例の実行による出力の例を示します。 スクリプトの実行が失敗した場合、PowerShell スクリプトがこのトピックの先頭にある要件の説明に従って有効になっていることを確認してください。
PS C:\> .\PartnerManagement.ps1
Make sure the PartyResolution sample application from the Orchestrations
sample directory is deployed and running.
By default it will be listed in the BizTalk Server Administration Console
with the application name: "BizTalk.Application.1"
Example Party "FedEx" should be created and enlisted with the "ShipmentRole".
You can view the results in the BizTalk Server Administration console.
Press <Enter> to unenlist and delete...
参照
Partiesロール リンクとサービス リンク ロール管理 (BizTalk Server Samples フォルダー)