【问题标题】:Is there a way to automate turning a BizTalk Receive Location on or off through code?有没有办法通过代码自动打开或关闭 BizTalk 接收位置?
【发布时间】:2010-12-03 16:07:43
【问题描述】:

有没有办法在 BizTalk 中自动打开或关闭接收位置?似乎应该有某种 API 或类似的东西来处理这种事情。我更喜欢在 C# 中工作,但 WMI 或某种脚本也可以。

【问题讨论】:

    标签: c# biztalk biztalk2006r2


    【解决方案1】:

    除了 ExplorerOM,正如您所发现的,您还可以使用 WMI 启用/禁用接收位置(并控制发送端口)。

    如果您有兴趣,我有一个示例 PowerShell 脚本,它显示了如何执行这些操作 here

    【讨论】:

    • 太好了,这绝对有效。选择越多越好。谢谢 tomasr。
    【解决方案2】:

    我找到了解决方案。看来 Microsoft.BizTalk.ExplorerOM.dll 是我想要的。以下是 BizTalk 文档的摘录,应该让其他人开始:

    using System;
    using Microsoft.BizTalk.ExplorerOM;
    public static void EnumerateOrchestrationArtifacts()
    {
        // Connect to the local BizTalk Management database
        BtsCatalogExplorer catalog = new BtsCatalogExplorer();
        catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;";
    
        // Enumerate all orchestrations and their ports/roles
        Console.WriteLine("ORCHESTRATIONS: ");
        foreach(BtsAssembly assembly in catalog.Assemblies)
        {
            foreach(BtsOrchestration orch in assembly.Orchestrations)
            {
    
                Console.WriteLine(" Name:{0}\r\n Host:{1}\r\n Status:{2}",
                    orch.FullName, orch.Host.Name, orch.Status);
    
                // Enumerate ports and operations
                foreach(OrchestrationPort port in orch.Ports)
                {
                    Console.WriteLine("\t{0} ({1})", 
                        port.Name, port.PortType.FullName);
    
                    foreach(PortTypeOperation operation in port.PortType.Operations)
                    {
                        Console.WriteLine("\t\t" + operation.Name);
                    }
                }
    
                // Enumerate used roles
                foreach(Role role in orch.UsedRoles)
                {
                    Console.WriteLine("\t{0} ({1})", 
                        role.Name, role.ServiceLinkType);
    
                    foreach(EnlistedParty enlistedparty in role.EnlistedParties)
                    {
                        Console.WriteLine("\t\t" + enlistedparty.Party.Name);
                    }
                }
    
                // Enumerate implemented roles
                foreach(Role role in orch.ImplementedRoles)
                {
                    Console.WriteLine("\t{0} ({1})", 
                        role.Name, role.ServiceLinkType);
                }
            }
        }
    }
    

    一个警告,显然这个 dll 不支持 64 位。由于我只是在编写一个简单的实用程序,因此对我来说没什么大不了的(只是编译为 32 位),但需要注意这一点。

    【讨论】:

    • 我可以使用远程访问 Biztalk Server 吗??
    • 嘿,Alhambraeidos,如果我理解正确,是的,你可以。我用它创建了一个小型 Windows 应用程序,让我可以选择接收位置并将其关闭。
    【解决方案3】:

    很高兴看到您似乎找到了解决方案。

    想提一个类似的替代方案,它也使用 Powershell、ExplorerOM 和 BizTalk API 将 BizTalk 工件设置为各种状态。

    接收位置是其中之一。

    该脚本接受 XML 配置文件,您可以在其中列出工件以及您希望将它们设置为什么状态。

    脚本已发布到 Microsoft 脚本中心: http://gallery.technet.microsoft.com/scriptcenter/Set-Artifact-Status-270f43a0

    【讨论】:

      【解决方案4】:

      回应 Alhambraeidos 的评论。以下是我在 Windows 应用中用于远程禁用接收位置的一些代码摘录:

          /// <summary>
          /// Gets or sets the biz talk catalog.
          /// </summary>
          /// <value>The biz talk catalog.</value>
          private BtsCatalogExplorer BizTalkCatalog { get; set; }
      
          /// <summary>
          /// Initializes the biz talk artifacts.
          /// </summary>
          private void InitializeBizTalkCatalogExplorer()
          {
              // Connect to the local BizTalk Management database
              BizTalkCatalog = new BtsCatalogExplorer();
              BizTalkCatalog.ConnectionString = "server=BiztalkDbServer;database=BizTalkMgmtDb;integrated security=true";
          }
      
      
          /// <summary>
          /// Gets the location from biz talk.
          /// </summary>
          /// <param name="locationName">Name of the location.</param>
          /// <returns></returns>
          private ReceiveLocation GetLocationFromBizTalk(string locationName)
          {
              ReceivePortCollection receivePorts = BizTalkCatalog.ReceivePorts;
              foreach (ReceivePort port in receivePorts)
              {
                  foreach (ReceiveLocation location in port.ReceiveLocations)
                  {
                      if (location.Name == locationName)
                      {
                          return location;
                      }
                  }
              }
      
              throw new ApplicationException("The following receive location could not be found in the BizTalk Database: " + locationName);
          }
      
      
          /// <summary>
          /// Turns the off receive location.
          /// </summary>
          /// <param name="vendorName">Name of the vendor.</param>
          public void TurnOffReceiveLocation(string vendorName)
          {
              ReceiveLocation location = Locations[vendorName].ReceiveLocation;
              location.Enable = false;
              BizTalkCatalog.SaveChanges();
          }
      

      您会注意到我遗漏了一些内容,例如我正在创建一个名为“Locations”的接收位置字典,但您应该能够明白这一点。该模式几乎适用于您想要与之交互的任何 BizTalk 对象。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-19
        相关资源
        最近更新 更多