SendPorts (BizTalk Server 範例)
SendPorts 範例示範如何使用 Microsoft.BizTalk.ExplorerOM 管理類別來列舉和管理傳送埠。
必要條件
您必須擁有BizTalk Server系統管理許可權,才能使用此範例中的系統管理物件。
Windows PowerShell腳本需要Windows PowerShell執行原則,才能允許腳本執行。 如需詳細資訊,請參閱 about_Execution_Policies。
此範例的用途
此範例示範如何使用來自 Microsoft.BizTalk.ExplorerOM命名空間的BtsCatalogExplorer和SendPort類別來管理BizTalk Server環境中的傳送埠。 此範例是以 Microsoft Visual C# 撰寫。 本主題也包含Windows PowerShell範例腳本。 此範例示範下列作業:
使用 BtsCatalogExplorer 類別連接到 BizTalk 管理資料庫。
建立名為 myStaticOnewaySendPort1 和 myDynamicTwowaySendPort1 的新傳送埠。 myStaticOnewaySendPort1,如其名稱所示,是靜態單向傳送埠。 它會建立為搭配範例目的地 URL 使用 HTTP 傳輸 http://sample1. myDynamicTwowaySendPort1 會建立為動態雙向傳送埠。
列舉BizTalk Server環境中的傳送埠。 這個範例列舉應該包含兩個新的傳送埠。
刪除兩個新的傳送埠。
設定新的傳送埠。 範例所示範的組態會套用至名為 myStaticOnewaySendPort1 的傳送埠。 範例所套用的組態包括下列各項:
啟用 [ 在埠處理之前要求訊息 ] 選項,以追蹤訊息本文。
啟用 [ 在埠處理後要求訊息 ] 選項,以追蹤訊息本文。
指定要在傳出訊息上使用之傳送埠的加密憑證。
針對一組訊息指定登記的篩選準則。
新增對應以轉換訊息。
變更兩個新的傳送埠上的傳送埠狀態。 執行範例會在 myStaticOnewaySendPort1 上進行下列狀態變更:
將狀態變更為已啟動。
將狀態變更為已停止。
將狀態變更為系結。 系結狀態與未列出的狀態相同。
此範例的位置
這個範例位於下列 SDK 位置:
<範例路徑>\管理員\ExplorerOM\SendPorts
下表顯示此範例中的檔案,並描述其用途。
檔案 | Description |
---|---|
SendPorts.cs | 此範例中示範之作業的 Visual C# 原始程式檔。 |
SendPorts.sln、SendPorts.csproj、SendPorts.suo | 此範例的方案和專案檔。 |
建置和執行此範例
建置此範例
在 Visual Studio 中,開啟方案檔 SendPorts.sln。
在主功能表上,按一下 [ 建置],然後按一下 [ 建置方案]。
執行此範例
開啟命令視窗並巡覽至下列資料夾:
<範例路徑>\管理員\ExplorerOM\SendPorts\bin\Debug
執行檔案 SendPorts.exe。
Windows PowerShell 指令碼範例
下列Windows PowerShell腳本片段可用來示範ExplorerOM類別的相同功能:
Function CreateSendPorts($Catalog)
{
#=== Register a trap handler to discard changes on exceptions ===#
$ErrorActionPreference="silentlycontinue"
trap { "Exception encountered:`r`n"; $_; "`r`nDiscarding Changes.`r`n";$Catalog.DiscardChanges();exit; }
#=== create a new static one-way send port using HTTP transport ===#
$myStaticOnewaySendPort = $Catalog.AddNewSendPort($false,$false)
$myStaticOnewaySendPort.Name = "myStaticOnewaySendPort1"
$myStaticOnewaySendPort.PrimaryTransport.TransportType = $catalog.ProtocolTypes["HTTP"]
$myStaticOnewaySendPort.PrimaryTransport.Address = "http://sample1"
$myStaticOnewaySendPort.SendPipeline = $Catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"]
#=== create a new dynamic two-way send port ===#
$myDynamicTwowaySendPort = $catalog.AddNewSendPort($true,$true)
$myDynamicTwowaySendPort.Name = "myDynamicTwowaySendPort1";
$myDynamicTwowaySendPort.SendPipeline = $Catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"];
$myDynamicTwowaySendPort.ReceivePipeline = $Catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLReceive"];
#=== Persist new ports to BizTalk configuration database ===#
Write-Host Adding $myStaticOnewaySendPort.Name...
Write-Host Adding $myDynamicTwowaySendPort.Name...
$catalog.SaveChanges();
Write-Host "`r`nCreateSendPorts() completed."
}
Function DeleteSendPorts($Catalog)
{
#=== Register a trap handler to discard changes on exceptions ===#
$ErrorActionPreference="silentlycontinue"
trap { "Exception encountered:`r`n"; $_; "`r`nDiscarding Changes.`r`n";$Catalog.DiscardChanges();exit; }
#=== Delete this sample's new send ports by name ===#
$Catalog.RemoveSendPort($Catalog.SendPorts["myStaticOnewaySendPort1"])
$Catalog.RemoveSendPort($Catalog.SendPorts["myDynamicTwowaySendPort1"])
#=== Persist changes to BizTalk configuration database ===#
$catalog.SaveChanges();
Write-Host "DeleteSendPorts() completed."
}
Function EnumerateSendPorts($Catalog)
{
#=== Display all send ports and their status info ===#
$catalog.SendPorts | format-table -Property Name, Status -autosize
Write-Host "EnumerateSendPorts`(`) completed."
}
Function ConfigureSendPort($Catalog)
{
#=== Register a trap handler to discard changes on exceptions ===#
$ErrorActionPreference="silentlycontinue"
trap { "Exception encountered:`r`n"; $_; "`r`nDiscarding Changes.`r`n";$Catalog.DiscardChanges();exit; }
$sendport = $catalog.SendPorts["myStaticOnewaySendPort1"];
#=== specify tracking settings for tracking ===#
Write-Host $sendport.Name: Enabling BeforeSendPipeline and AfterSendPipeline message body tracking.
$sendport.Tracking = ([Microsoft.BizTalk.ExplorerOM.TrackingTypes] "BeforeSendPipeline" -bor
[Microsoft.BizTalk.ExplorerOM.TrackingTypes] "AfterSendPipeline")
#=== specify an encryption certificate for outgoing messages ===#
Write-Host $sendport.Name: Adding a encryption certificate
foreach ($certificate in $catalog.Certificates)
{
if ($certificate.UsageType -eq [Microsoft.BizTalk.ExplorerOM.CertUsageType] "Encryption")
{
$sendport.EncryptionCert = $certificate
}
}
#=== specify filters for content-based routing ===#
Write-Host $sendport.Name: Adding a filter
$sendport.Filter = "<Filter><Group>" +
"<Statement Property='SMTP.Subject' Operator='0' Value='Purchase Order'/>" +
"<Statement Property='SMTP.From' Operator='0' Value='Customer'/>" +
"</Group></Filter>"
#=== specify transform maps for document normalization ===#
foreach ($transform in $catalog.Transforms)
{
if (($transform.SourceSchema.FullName -ieq "myPO") -and (transform.TargetSchema.FullName -ieq "partnerPO"))
{
Write-Host $sendport.Name: Adding a transform
$sendport.OutboundTransforms.Add($transform)
}
}
#=== Persist all changes to BizTalk configuration database ===#
Write-Host $sendport.Name: Saving changes
$catalog.SaveChanges();
Write-Host "`r`nConfigureSendPort() completed."
}
Function ChangeSendPortStatus($Catalog)
{
#=== Register a trap handler to discard changes on exceptions ===#
$ErrorActionPreference="silentlycontinue"
trap { "Exception encountered:`r`n"; $_; "`r`nDiscarding Changes.`r`n";$Catalog.DiscardChanges();exit; }
$sendport = $catalog.SendPorts["myStaticOnewaySendPort1"];
#=== start the send port to begin processing messages ===#
$sendport.Status = [Microsoft.BizTalk.ExplorerOM.PortStatus] "Started"
Write-Host Changing ($sendport.Name) status to ($sendport.Status)...
$catalog.SaveChanges();
Write-Host Complete.
#=== stop the send port to stop processing and suspend messages ===#
$sendport.Status = [Microsoft.BizTalk.ExplorerOM.PortStatus] "Stopped"
Write-Host Changing ($sendport.Name) status to ($sendport.Status)...
$catalog.SaveChanges();
Write-Host Complete.
#=== unenlist the send port to stop processing and discard messages ===#
$sendport.Status = [Microsoft.BizTalk.ExplorerOM.PortStatus] "Bound"
Write-Host Changing ($sendport.Name) status to ($sendport.Status)`(Unenlisted`)...
$catalog.SaveChanges();
Write-Host Complete.
}
#=== Main Script Body ===#
#=== 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"
#=== Exercise the CreateSendPorts function to create the two new ports ===#
Write-Host "`r`n========================="
Write-Host "=== CreateSendPorts`(`) ==="
Write-Host "=========================`r`n"
CreateSendPorts $Catalog
#=== Enumerate all send ports to view the two new ports ===#
Write-Host "`r`n============================"
Write-Host "=== EnumerateSendPorts`(`) ==="
Write-Host "============================`r`n"
EnumerateSendPorts $Catalog
#=== Add some configuration to the static send port ===#
Write-Host "`r`n==========================="
Write-Host "=== ConfigureSendPort`(`) ==="
Write-Host "===========================`r`n"
ConfigureSendPort $Catalog
#=== Cycle through some status changes on the static send port ===#
Write-Host "`r`n=============================="
Write-Host "=== ChangeSendPortStatus`(`) ==="
Write-Host "==============================`r`n"
ChangeSendPortStatus $Catalog
#=== Delete the two new ports ===#
Write-Host "`r`n========================="
Write-Host "=== DeleteSendPorts`(`) ==="
Write-Host "=========================`r`n"
DeleteSendPorts $Catalog
Write-Host
以下是執行 Windows PowerShell 腳本範例的預期輸出範例。
PS C:\> & 'C:\SendPorts.ps1'
=========================
=== CreateSendPorts() ===
=========================
Adding myStaticOnewaySendPort1 ...
Adding myDynamicTwowaySendPort1 ...
CreateSendPorts() completed.
============================
=== EnumerateSendPorts() ===
============================
Name Status
---- ------
ResendPort Started
HelloWorldSendPort Started
ToCustomerSendPort Started
CBRUSSendPort Started
CBRCANSendPort Started
SendportCANOrders Bound
myStaticOnewaySendPort1 Bound
myDynamicTwowaySendPort1 Bound
EnumerateSendPorts() completed.
===========================
=== ConfigureSendPort() ===
===========================
myStaticOnewaySendPort1 : Enabling BeforeSendPipeline and AfterSendPipeline message body tracking.
myStaticOnewaySendPort1 : Adding a encryption certificate
myStaticOnewaySendPort1 : Adding a filter
myStaticOnewaySendPort1 : Saving changes
ConfigureSendPort() completed.
==============================
=== ChangeSendPortStatus() ===
==============================
Changing myStaticOnewaySendPort1 status to Started ...
Complete.
Changing myStaticOnewaySendPort1 status to Stopped ...
Complete.
Changing myStaticOnewaySendPort1 status to Bound (Unenlisted)...
Complete.
=========================
=== DeleteSendPorts() ===
=========================
DeleteSendPorts() completed.