ReceiveLocations (BizTalk Server 範例)
ReceiveLocations 範例示範如何使用ExplorerOM管理物件,在BizTalk Server環境中建立接收位置。 如需一般接收位置的詳細資訊,請參閱 接收位置。
必要條件
您必須擁有BizTalk Server系統管理許可權,才能使用此範例中的系統管理物件。
Windows PowerShell腳本需要Windows PowerShell執行原則,才能允許腳本執行。 如需詳細資訊,請參閱 檢查執行原則。
此範例的用途
此範例示範如何使用 ExplorerOM 系統管理類別來建立和設定接收埠和接收位置。 本主題也包含Windows PowerShell範例腳本。 此範例會執行下列作業:
建立名為 「My Receive Port」 的新接收埠。
建立與新埠相關聯的新接收位置,並設定為使用 HTTP 傳輸通訊協定。
此範例也包含刪除和列舉接收埠和位置的範例程式。
此範例的位置
這個範例位於下列 SDK 位置:
<範例路徑>\管理員\ExplorerOM\ReceiveLocations
下表顯示此範例中的檔案,並描述其用途。
檔案 | Description |
---|---|
ReceiveLocations.cs | 此範例中示範之作業的 Visual C# 原始程式檔。 |
ReceiveLocations.sln 和 ReceiveLocations.csproj | 此範例的解決方案和專案檔。 |
建置和執行此範例
建置此範例
在 Visual Studio 中,開啟方案檔 ReceiveLocations.sln。
在 [建置] 功能表上,按一下 [建置方案]。
執行此範例
使用BizTalk Server系統管理許可權開啟命令提示字元。
變更為 <Samples> \管理員\ExplorerOM\ReceiveLocations\bin\debug 目錄。
執行 ReceiveLocations.exe。
使用 BizTalk Server 管理主控台來檢視新的接收埠和接收位置。
Windows PowerShell 指令碼範例
下列 PowerShell 範例腳本示範與 Visual C# 版本相同的作業。 請確定腳本執行原則已正確設定,如本主題的需求一節中所述。
#==================================================================#
#=== ===#
#=== Create a new receive port named "My Receive Port" as an ===#
#=== example. ===#
#=== ===#
#=== A new receive location will also be created and associated ===#
#=== with the receive port. ===#
#=== ===#
#==================================================================#
Function CreateAndConfigureReceiveLocation()
{
$myreceivePort = $catalog.AddNewReceivePort($false)
#=== Note that if you don’t set the name property for the receieve port, ===#
#=== it will create a new receive location and add it to the receive ===#
#=== port. ===#
$myreceivePort.Name = "My Receive Port"
#=== Create a new receive location and add it to the receive port ===#
$myreceiveLocation = $myreceivePort.AddNewReceiveLocation()
foreach ($handler in $catalog.ReceiveHandlers)
{
if ($handler.TransportType.Name -eq "HTTP")
{
$myreceiveLocation.ReceiveHandler = $handler
break
}
}
#=== Associate a transport protocol and URI with the receive location. ===#
$myreceiveLocation.TransportType = $catalog.ProtocolTypes["HTTP"]
$myreceiveLocation.Address = "/home"
#=== Assign the first receive pipeline found to process the message. ===#
foreach ($pipeline in $catalog.Pipelines)
{
if ($pipeline.Type -eq [Microsoft.Biztalk.ExplorerOM.PipelineType] "Receive")
{
$myreceiveLocation.ReceivePipeline = $pipeline
break
}
#=== Enable the receive location. ===#
$myreceiveLocation.Enable = $true
#=== Optional Properties ===#
$myreceiveLocation.FragmentMessages = [Microsoft.BizTalk.ExplorerOM.Fragmentation] "Yes"
$myreceiveLocation.ServiceWindowEnabled = $false
}
#=== 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)
{
#=== Enumerate the receive locations. ===#
foreach ($location in $receivePort.ReceiveLocations)
{
if (($location.Name -eq "Receive Location1") -and ($location.IsPrimary -eq $false))
{
$receivePort.RemoveReceiveLocation($location)
}
}
$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 and their receive locations. ===#
#=== ===#
#================================================================#
Function EnumerateReceiveLocations
{
#=== Enumerate the receive locations in each of the receive ports. ===#
foreach ($receivePort in $catalog.ReceivePorts)
{
Write-host "`r`n$($receivePort.Name)"
#=== Enumerate the receive locations. ===#
foreach ($location in $receivePort.ReceiveLocations)
{
Write-Host "`t$($location.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 with its new receive location ===#
CreateAndConfigureReceiveLocation
Write-Host "`r`n`"My Receive Port`" created."
#=== Enumerate each receive port along with its receive locations ===#
Write-Host "`r`nEnumerating all receive ports...`r`n"
EnumerateReceiveLocations
#=== Prompt before removing the new example receive port and location ===#
Write-Host "`r`nPress <ENTER> to delete `"My Receive Port`"..."
Read-Host
DeleteReceivePort
#=== Enumerate again to show the receive port and location was removed ===#
Write-Host "`r`nEnumerating all receive ports to show `"My Receive Port`" was removed...`r`n"
EnumerateReceiveLocations
以下是 PowerShell 腳本執行的範例輸出,其中顯示正在建立和刪除的接收埠和位置:
PS C:\> .\ReceiveLocations.ps1
"My Receive Port" created.
Enumerating all receive ports...
BatchControlMessageRecvPort
BatchControlMessageRecvLoc
ResendReceivePort
ResendReceiveLocation
HelloWorldReceivePort
HelloWorldReceiveLocation
CBRReceivePort
CBRReceiveLocation
RP_ReceivePOFromInternal
RL_ReceivePOFromInternal
RP_ShipmentAgency1_OrderFiles
RL_ShipmentAgency1_OrderFiles
RP_ShipmentAgency2_OrderFiles
RL_ShipmentAgency2_OrderFiles
RP_ReceivePOFromBuyer
RL_ReceivePOFromBuyer
RP_Receive_ShipmentAgency_Ack
RL_Receive_ShipmentAgency_Ack
My Receive Port
Receive Location1
Press <ENTER> to delete "My Receive Port"...
Enumerating all receive ports to show "My Receive Port" was removed...
BatchControlMessageRecvPort
BatchControlMessageRecvLoc
ResendReceivePort
ResendReceiveLocation
HelloWorldReceivePort
HelloWorldReceiveLocation
CBRReceivePort
CBRReceiveLocation
RP_ReceivePOFromInternal
RL_ReceivePOFromInternal
RP_ShipmentAgency1_OrderFiles
RL_ShipmentAgency1_OrderFiles
RP_ShipmentAgency2_OrderFiles
RL_ShipmentAgency2_OrderFiles
RP_ReceivePOFromBuyer
RL_ReceivePOFromBuyer
RP_Receive_ShipmentAgency_Ack
RL_Receive_ShipmentAgency_Ack