Compartir a través de


ReceivePorts (ejemplo de BizTalk Server)

En el ejemplo ReceivePorts se muestra cómo crear un puerto de recepción mediante las clases administrativas ExplorerOM .

Requisitos previos

  • Debe tener BizTalk Server privilegios administrativos para usar los objetos administrativos de este ejemplo.

  • El script de Windows PowerShell requiere que la directiva de ejecución de Windows PowerShell permita la ejecución de scripts. Para obtener más información, vea about_Execution_Policies.

Descripción del ejemplo

En este ejemplo se muestra cómo usar las clases BtsCatalogExplorer y ReceivePort del espacio de nombres Microsoft.BizTalk.ExplorerOM para agregar un nuevo puerto de recepción a BizTalk Server. El ejemplo se escribe en Microsoft Visual C#. En este tema también se incluye un script de ejemplo de Windows PowerShell. El ejemplo muestra las siguientes operaciones:

  • Conectarse a la base de datos de administración de BizTalk mediante la clase BtsCatalogExplorer .

  • Agregar un nuevo puerto de recepción mediante el método AddNewReceivePort .

  • Enumeración de los puertos de recepción.

  • Eliminación de los puertos de recepción.

Dónde encontrar este ejemplo

El ejemplo se encuentra en la siguiente ubicación del SDK:

<Ruta de acceso de> ejemplos\Administración\ExplorerOM\ReceivePorts

En la tabla siguiente se enumeran los archivos del ejemplo y se describe su propósito.

Archivos Descripción
ReceivePorts.cs Archivo de origen de Visual C# para las operaciones que se muestran en este ejemplo.
ReceivePorts.sln y ReceivePorts.csproj Archivo de solución y proyecto para el ejemplo.

Compilación de este ejemplo

  1. En Visual Studio, abra el archivo de solución ReceivePorts.sln.

  2. En el menú Compilar , haga clic en Compilar solución.

Ejecutar esta muestra

  1. Abra una ventana de comandos y desplácese a la siguiente carpeta:

    <Ruta de acceso de> ejemplos\Administración\ExplorerOM\ReceivePorts\bin\Debug

  2. Ejecute el archivo ReceivePorts.exe. El nuevo puerto de recepción debe crearse y mostrarse en la enumeración de puertos. Después de la enumeración, el puerto de recepción se quita inmediatamente.

Ejemplo de un script de Windows PowerShell

El siguiente script de ejemplo de Windows PowerShell se puede usar para mostrar las mismas características de las clases 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

Éste es un ejemplo muestra la ejecución del script de Windows PowerShell para crear el nuevo puerto de recepción:

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

Consulte también

Admin\ExplorerOM (carpeta de ejemplos de BizTalk Server)