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
下表顯示此範例中的檔案,並描述其用途。
檔案 | Description |
---|---|
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