ReceivePorts(BizTalk Server 示例)
ReceivePorts 示例演示如何使用 ExplorerOM 管理类创建新的接收端口。
必备条件
必须具有BizTalk Server管理权限才能使用此示例中的管理对象。
Windows PowerShell 脚本要求 Windows PowerShell 执行策略允许脚本执行。 有关详细信息,请参阅 about_Execution_Policies。
本示例的用途
此示例演示如何使用 Microsoft.BizTalk.ExplorerOM 命名空间中的 BtsCatalogExplorer 和 ReceivePort 类向BizTalk Server添加新的接收端口。 此示例是用 Microsoft Visual C# 编写的。 本主题中还包含 Windows PowerShell 示例脚本。 本示例将演示以下操作:
使用 BtsCatalogExplorer 类连接到 BizTalk 管理数据库。
使用 AddNewReceivePort 方法添加新的接收端口。
枚举接收端口。
删除接收端口。
本示例的所在位置
本示例位于以下 SDK 位置中:
<示例路径>\管理员\ExplorerOM\ReceivePorts
下表显示了本示例中的文件及其用途说明:
文件 | 说明 |
---|---|
ReceivePorts.cs | 此示例中演示的操作的 Visual C# 源文件。 |
ReceivePorts.sln 和 ReceivePorts.csproj | 示例的解决方案和项目文件。 |
生成此示例
在 Visual Studio 中,打开解决方案文件 ReceivePorts.sln。
在“生成”菜单中,单击“生成解决方案”。
运行此示例
打开命令窗口并导航到以下文件夹:
<示例路径>\管理员\ExplorerOM\ReceivePorts\bin\Debug
ReceivePorts.exe 运行文件。 应创建新的接收端口并在端口枚举中显示。 枚举之后,接收端口立即被删除。
Windows Powershell 脚本示例
以下Windows PowerShell示例脚本可用于演示 ExplorerOM 类的相同功能:
#==================================================================#
#=== ===#
#=== Create a new receive port named "My Receive Port". ===#
#=== ===#
#==================================================================#
Function CreateReceivePort()
{
#=== Passing false here creates a one-way receive port opposed to a two-way ===#
$myreceivePort = $catalog.AddNewReceivePort($false)
$myreceivePort.Name = "My Receive Port"
$myreceivePort.Tracking = [Microsoft.BizTalk.ExplorerOM.TrackingTypes] "AfterReceivePipeline"
#=== Try to commit the changes made so far. If the commit fails, ===#
#=== roll back all changes. ===#
$catalog.SaveChanges()
}
#===============================================================#
#=== ===#
#=== Delete the receive port named "My Receive Port" ===#
#=== ===#
#===============================================================#
Function DeleteReceivePort
{
$receivePort = $catalog.ReceivePorts["My Receive Port"]
if ($receivePort -ne $null)
{
$catalog.RemoveReceivePort($receivePort)
#=== Try to commit the changes made so far. If the commit fails, ===#
#=== roll back all changes in the trap handler. ===#
$catalog.SaveChanges()
}
}
#================================================================#
#=== ===#
#=== Enumerate the receive ports. ===#
#=== ===#
#================================================================#
Function EnumerateReceivePorts
{
#=== Enumerate the receive ports. ===#
foreach ($receivePort in $catalog.ReceivePorts)
{
Write-host "`r`n$($receivePort.Name)"
}
Write-host ""
}
#===================#
#=== 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"
#==================================================================#
#=== Register a trap handler to discard changes on exceptions ===#
#=== Execution will continue in the event we want to delete the ===#
#=== receive port. ===#
#==================================================================#
$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 receive port...`r`n"
$Catalog.DiscardChanges()
}
#=== Create the new receive port ===#
Write-Host "`r`nAttempting to create `"My Receive Port`"..."
CreateReceivePort
#=== Enumerate each receive port ===#
Write-Host "`r`nEnumerating all receive ports...`r`n"
EnumerateReceivePorts
#=== Prompt before removing the new example receive port ===#
Write-Host "`r`nPress <ENTER> to delete `"My Receive Port`"..."
Read-Host
DeleteReceivePort
#=== Enumerate again to show the receive port was removed ===#
Write-Host "`r`nEnumerating all receive ports to show `"My Receive Port`" was removed...`r`n"
EnumerateReceivePorts
这是运行 Windows PowerShell 脚本以创建新接收端口的示例:
PS C:\> .\receiveports.ps1
Attempting to create "My Receive Port"...
Enumerating all receive ports...
BatchControlMessageRecvPort
ResendReceivePort
HelloWorldReceivePort
CBRReceivePort
RP_ReceivePOFromInternal
RP_ShipmentAgency1_OrderFiles
RP_ShipmentAgency2_OrderFiles
RP_ReceivePOFromBuyer
RP_Receive_ShipmentAgency_Ack
My Receive Port
Press <ENTER> to delete "My Receive Port"...
Enumerating all receive ports to show "My Receive Port" was removed...
BatchControlMessageRecvPort
ResendReceivePort
HelloWorldReceivePort
CBRReceivePort
RP_ReceivePOFromInternal
RP_ShipmentAgency1_OrderFiles
RP_ShipmentAgency2_OrderFiles
RP_ReceivePOFromBuyer
RP_Receive_ShipmentAgency_Ack