2017-08-08 42 views
0
  ############################################################# 
      # This function will create a handler for a specific 
      # adapter on the new host, so these get used for processing. 
      # [direction]: 'Receive','Send' 
      ############################################################# 
      function CreateBizTalkAdapterHandler(
       [string]$adapterName, 
       [string]$direction, 
       [string]$hostName, 
       [string]$originalDefaulHostName, 
       [boolean]$isDefaultHandler) 
       #[boolean]$removeOriginalHostInstance) 
      { 
       if($direction -eq 'Receive') 
       { 
        [System.Management.ManagementObject]$objAdapterHandler = ([WmiClass]"root/MicrosoftBizTalkServer:MSBTS_ReceiveHandler").CreateInstance() 
        $objAdapterHandler["AdapterName"] = $adapterName 
        $objAdapterHandler["HostName"] = $hostName 
       } 
       else 
       { 
        [System.Management.ManagementObject]$objAdapterHandler = ([WmiClass]"root/MicrosoftBizTalkServer:MSBTS_SendHandler2").CreateInstance() 
        $objAdapterHandler["AdapterName"] = $adapterName 
        $objAdapterHandler["HostName"] = $hostName 
        $objAdapterHandler["IsDefault"] = $isDefaultHandler 
       } 

       try 
       { 
        $putOptions = new-Object System.Management.PutOptions 
        $putOptions.Type = [System.Management.PutType]::CreateOnly; 

        [Type[]] $targetTypes = New-Object System.Type[] 1 
        $targetTypes[0] = $putOptions.GetType() 

        $sysMgmtAssemblyName = "System.Management" 
        $sysMgmtAssembly = [System.Reflection.Assembly]::LoadWithPartialName($sysMgmtAssemblyName) 
        $objAdapterHandlerType = $sysMgmtAssembly.GetType("System.Management.ManagementObject") 

        [Reflection.MethodInfo] $methodInfo = $objAdapterHandlerType.GetMethod("Put", $targetTypes) 
        $methodInfo.Invoke($objAdapterHandler, $putOptions) 

        Write-Host "$adapterName $direction Handler for $hostName was successfully created" -Fore DarkGreen 
       } 
       catch [System.Management.Automation.RuntimeException] 
       { 
        if ($_.Exception.Message.Contains("The specified BizTalk Host is already a receive handler for this adapter.") -eq $true) 
        { 
         Write-Host "$hostName is already a $direction Handler for $adapterName adapter." -Fore DarkRed 
        } 
        elseif($_.Exception.Message.Contains("The specified BizTalk Host is already a send handler for this adapter.") -eq $true) 
        { 
         Write-Host "$hostName is already a $direction Handler for $adapterName adapter." -Fore DarkRed 
        } 
        else { 
         write-Error "$adapterName $direction Handler for $hostName could not be created: $_.Exception.ToString()" 
        } 
       } 

       #if($removeOriginalHostInstance) 
       #{ 
        #DeleteBizTalkAdapterHandler $adapterName $direction $originalDefaulHostName 
       #} 
      } 

當我運行CreateBizTalkAdapterHandler錯誤

CreateBizTalkAdapterHandler -adapterName "WCF-WebHttp" -direction "Send" -hostName "ServiceProcessing" -originalDefaulHostName "BizTalkServerApplication" -isDefaultHandler 0 

是創建ServiceProcessing發送處理程序,但是當我使用

CreateBizTalkAdapterHandler -adapterName "WCF_WSHttp" -direction "Send" -hostName "PMProcessing" -originalDefaulHostName "BizTalkServerApplication" -isDefaultHandler 0 

我收到的時候我正在處理 「WCF-WSHttp」 錯誤適配器:

CreateBizTalkAdapterHandler:WCF_WSHttp無法創建用於PMOServiceProcessing的發送處理程序:使用 「2」參數調用「Invoke」的異常:「沒有找到指定鍵的實例。 「。Exception.ToString() At line:3 char:1 + CreateBizTalkAdapterHandler -adapterName」WCF_WSHttp「-direction」Sen ... +〜「 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [寫錯誤],WriteErrorException + FullyQualifiedErrorId:Microsoft.PowerShell.Commands.WriteErrorException,CreateBizTalkAdapterHandler

+0

對不起人們..我找到解決方案!它與adapterName「WCF_WSHttp」而不是adapterName「WCF-WSHttp」的拼寫錯誤。 –

回答

0
CreateBizTalkAdapterHandler -adapterName "WCF-WSHttp" -direction "Send" -hostName "PMProcessing" -originalDefaulHostName "BizTalkServerApplication" -isDefaultHandler 0