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 | 示例的解决方案文件和项目文件。 |
生成并运行本示例
在生成本示例之前,您需要进行四次代码修改,以便为 BizTalk Server 自定义本示例。 此操作是必须的,因为该示例对与参与方相关的发送端口使用任意名称,并且在登记时也使用任意角色名称。 因此,您需要为此示例提供有效名称。 为了演示此示例,本主题介绍首先从以下目录生成 PartyResolution 示例: <Samples Path>\Orchestrations\PartyResolution。 此方法用于确保在 BizTalk Server 上存在有效的角色名称和发送端口名称,以演示示例过程。
生成示例
首先,确保已生成并已初始化 PartyResolution 示例,以便此示例能够使用有效的角色名称和发送端口名称。 这在 PartyResolution (BizTalk Server 示例) 中标题为“生成和初始化此示例”的部分进行了说明。
在 Visual Studio 中,打开解决方案文件 PartnerManagement.sln。
在解决方案资源管理器中,打开源文件 PartnerManagement.cs。
向下滚动到名为 CreateParty 的 函数,插入 PartyResolution 示例中的两个发送端口名称,或使用 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 循环,以便它在 Supplier 程序集中搜索名为“ShipmentRole”的角色以用于登记。 以下代码示例演示如何改为使用来自 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 循环以搜索 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 创建并登记新参与方之后,此示例用于立即注销此参与方并将其删除。 将以下代码更改添加到main过程以暂停执行,并允许在 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管理控制台中,将树视图导航到“应用程序\BizTalk 应用程序 1\角色链接”下的“ShipmentRole”。 双击“ ShipmentRole ”,并注意 “ShipmentAgency1 已映射到 SupplierAdvice 操作”, “ShipmentAgency2 ”映射到登记中的 “SupplierOrder ”操作。
在命令窗口中,按 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...