Compartir a través de


ReceiveLocations (ejemplo de BizTalk Server)

En el ejemplo ReceiveLocations se muestra cómo crear ubicaciones de recepción en el entorno de BizTalk Server mediante los objetos de administración explorerOM. Para obtener más información sobre las ubicaciones de recepción en general, consulte Ubicaciones de recepción.

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 Examinar la directiva de ejecución.

Descripción del ejemplo

En este ejemplo se muestra el uso de las clases administrativas ExplorerOM para crear y configurar puertos de recepción y ubicaciones de recepción. En este tema también se incluye un script de ejemplo de Windows PowerShell. El ejemplo realiza las siguientes operaciones:

  • Crear un nuevo puerto de recepción denominado “Mi puerto de recepción”.

  • Crear una nueva ubicación de recepción asociada con el nuevo puerto y configurada para usar el protocolo de transporte HTTP.

  • En este ejemplo también se incluyen procedimientos de ejemplo para eliminar y enumerar puertos y ubicaciones de recepción.

Dónde encontrar este ejemplo

Este ejemplo se encuentra en la siguiente ubicación de SDK:

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

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

Archivos Descripción
ReceiveLocations.cs Archivo de código fuente de Visual C# para las operaciones mostradas en este ejemplo.
ReceiveLocations.sln y ReceiveLocations.csproj Archivos de solución y proyecto para este ejemplo.

Generación y ejecución del ejemplo

Procedimiento para generar este ejemplo

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

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

Para ejecutar el ejemplo

  1. Abra un símbolo del sistema con BizTalk Server privilegios administrativos.

  2. Cambie al < directorio Samples>\Administración\ExplorerOM\ReceiveLocations\bin\debug.

  3. Ejecute ReceiveLocations.exe.

  4. Vea el nuevo puerto de recepción y la ubicación de recepción con la consola de administración de BizTalk Server.

Ejemplo de un script de Windows PowerShell

El siguiente script de ejemplo de PowerShell muestra las mismas operaciones que la versión de Visual C#. Asegúrese de que la política de ejecución de scripts se ha configurado correctamente, tal como se indica en la sección de requisitos de este tema.

#==================================================================#
#===                                                            ===#
#=== 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

Aquí se muestra un ejemplo de la ejecución de scripts de PowerShell que muestra el puerto de recepción y la ubicación que se están creando y eliminando:

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

Consulte también

Ubicaciones de recepciónAdministración-ExplorerOM (carpeta de ejemplos de BizTalk Server)