Condividi tramite


ReceiveLocations (esempio di BizTalk Server)

L'esempio ReceiveLocations illustra come creare percorsi di ricezione nell'ambiente BizTalk Server usando gli oggetti di amministrazione ExplorerOM. Per altre informazioni sui percorsi di ricezione in generale, vedere Località di ricezione.

Prerequisiti

  • È necessario disporre di BizTalk Server privilegi amministrativi per usare gli oggetti amministrativi in questo esempio.

  • L'esecuzione dello script di Windows PowerShell richiede i criteri di esecuzione di Windows PowerShell. Per ulteriori informazioni, vedere la pagina relativa all' analisi dei criteri di esecuzione.

Scopo dell'esempio

Questo esempio illustra l'uso delle classi amministrative ExplorerOM per creare e configurare le porte di ricezione e le posizioni di ricezione. In questo argomento è inoltre incluso uno script di esempio Windows PowerShell. Nell'esempio vengono eseguite le operazioni seguenti:

  • Creazione di una nuova porta di ricezione denominata “My Receive Port”.

  • Creazione di un nuovo indirizzo di ricezione associato alla nuova porta e configurato per l'utilizzo del protocollo di trasporto HTTP.

  • Nell'esempio sono inoltre disponibili procedure per l'eliminazione e l'enumerazione di porte e indirizzi di ricezione.

Percorso dell'esempio

L'esempio è disponibile nel percorso SDK seguente:

<Percorso esempi> \Amministrazione\ExplorerOM\ReceiveLocations

Nella seguente tabella sono riportati i file inclusi nell'esempio e ne viene descritto lo scopo.

File Descrizione
ReceiveLocations.cs File di origine Visual C# per le operazioni illustrate in questo esempio.
ReceiveLocations.sln e ReceiveLocations.csproj File di soluzione e di progetto per l'esempio.

Compilazione ed esecuzione dell'esempio

Per generare l'esempio

  1. In Visual Studio aprire il file della soluzione ReceiveLocations.sln.

  2. Nel menu Compila scegliere Compila soluzione.

Per eseguire questo esempio

  1. Aprire un prompt dei comandi con BizTalk Server privilegi amministrativi.

  2. Passare alla < directory Samples>\Amministrazione\ExplorerOM\ReceiveLocations\bin\debug.

  3. Eseguire ReceiveLocations.exe.

  4. Visualizzare la nuova porta di ricezione e la nuova posizione di ricezione con la console di amministrazione di BizTalk Server.

Esempio di script di Windows PowerShell

Lo script di esempio di PowerShell seguente illustra le stesse operazioni della versione di Visual C#. Assicurarsi che i criteri di esecuzione dello script siano stati configurati in modo conforme ai requisiti indicati all'inizio dell'argomento.

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

Di seguito è riportato l'output di esempio in seguito all'esecuzione dello script PowerShell, in cui viene illustrata la creazione e la successiva eliminazione della porta e dell'indirizzo di ricezione:

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

Vedere anche

Percorsi di ricezioneAmministrazione-ExplorerOM (cartella degli esempi di BizTalk Server)