0

我有一个程序可以查询 BizTalk 资源的状态,特别是 ReceiveLocations 组件。当我运行示例程序(从 C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\SDK\Samples\Admin\WMI\Enumerate Receive Locations 获得)我得到错误

无效的命名空间

在线上 :

ManagementObjectCollection QueryCol = Searcher.Get();

堆栈跟踪

at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at Microsoft.Samples.BizTalk.WmiAdmin.EnumerateWMIClasses.Main(String[] args) in 
C:\Users\usename\Desktop\BIZTALK\CSharp\EnumRLs.cs:line 114

这是查询 BizTalk 服务的完整程序:

[STAThread]
    static void Main(string[] args)
    {
        // Display help information 
        if (args.Length > 0)
        {
                if (args[0] == "/?") 
                {
                    ....
                    ....
                }
        }

        try 
        {   
            //Create the WMI search object.
            ManagementObjectSearcher Searcher = new ManagementObjectSearcher();

            // create the scope node so we can set the WMI root node correctly.
            ManagementScope Scope = new ManagementScope("root\\"+server+"");
            Searcher.Scope = Scope;
        
            // Build a Query to enumerate the MSBTS_ReceiveLocation instances if an argument
            // is supplied use it to select only the matching RL.
            SelectQuery Query = new SelectQuery(); 
            if (args.Length == 0) 
                Query.QueryString="SELECT * FROM MSBTS_ReceiveLocation";
            else
                Query.QueryString="SELECT * FROM MSBTS_ReceiveLocation WHERE Name = '" + args[0] + "'";

            // Set the query for the searcher.
            Searcher.Query = Query;

            // Execute the query and determine if any results were obtained.
            ManagementObjectCollection QueryCol = Searcher.Get();

            // Use a bool to tell if we enter the for loop
            // below because Count property is not supported
            bool ReceiveLocationFound = false;

            // Enumerate all properties.
            foreach (ManagementBaseObject envVar in QueryCol)
            {
                // There is at least one Receive Location
                ReceiveLocationFound = true;

                Console.WriteLine("**************************************************");
                Console.WriteLine("Receive Location:  {0}", envVar["Name"]);
                Console.WriteLine("**************************************************");

                PropertyDataCollection envVarProperties = envVar.Properties;
                Console.WriteLine("Output in the form of: Property: {Value}");
            
                foreach (PropertyData envVarProperty in envVarProperties) 
                {                   
                    Console.WriteLine(envVarProperty.Name+ ":\t" + envVarProperty.Value);
                }
            }
                
            if (!ReceiveLocationFound) 
            {
                Console.WriteLine("No receive locations found matching the specified name.");
            } 
        }

        catch(Exception excep)
        {
            Console.WriteLine(excep.ToString());
        }
        
        Console.WriteLine("\r\n\r\nPress Enter to continue...");
        Console.Read();
        }

我已经在 WMI 查询正在工作的单独 MVC 应用程序中尝试了代码,但我得到了同样的错误。然而,MVC 应用程序中的 WMI 查询用于查询远程服务器磁盘统计信息,而不是 BizTalk Server 服务。我已经逐步完成了程序,查询 对象显示了这个: https ://drive.google.com/file/d/1natMNMkHP2KVUzt60sZSRjU3ecthSPox/view?usp=sharing

我错过了什么?

我需要配置什么特定的东西来查询 System.Management 命名空间之外的 BizTalk 资源,或者它与示例代码本身有关吗?

4

0 回答 0