locked
How to read remote BizTalk server data using BizTalk .net class references ? RRS feed

  • Question

  • I am tring to read remote biztalk server data.

    Is it possible to read remote server data from BizTalk .net References?

    or any alternative way to read the same.


    Regards, Sagar Kakade http://www.me-ensemblo.com

    Thursday, January 22, 2015 1:34 PM

Answers

  • I don't think you can use " BtsCatalogExplorer" for get the details of message instances status like suspended or active. You got to either use WMI or SQL.

    Following code uses WMI classes in .NET to get the suspended instance details and active instance details. You can modify this code to suit your need:

    System.Management.ManagementScope oMs;
    System.Management.ObjectQuery queryWMISuspended;
    System.Management.ObjectQuery queryWMIActive;
    System.Management.ManagementObjectSearcher searcher;
    System.Management.ManagementObjectCollection queryResultSuspended;
    System.Management.ManagementObjectCollection queryResultActive;
    try
    {
        System.Management.ConnectionOptions connOption = new System.Management.ConnectionOptions();
        //connOption.Username = @"*****";
        //connOption.Password = "*****";
        connOption.Impersonation = System.Management.ImpersonationLevel.Impersonate;
        connOption.Authentication = System.Management.AuthenticationLevel.Packet;
        connOption.EnablePrivileges = true;
    
        //Replace this with your servername
        string serverName = "localhost";
       
        oMs = new System.Management.ManagementScope(@"\\" + serverName + @"\root\MicrosoftBizTalkServer", connOption);
        //oMs = new System.Management.ManagementScope(@"\\" + serverName + @"\root\cimv2", connOption);
    
        queryWMISuspended = new System.Management.ObjectQuery("SELECT * FROM MSBTS_ServiceInstance where ServiceStatus=4 AND ServiceClass = 4");
        searcher = new System.Management.ManagementObjectSearcher(oMs, queryWMISuspended);
        queryResultSuspended = searcher.Get();
    
        //Following code will give you the count of suspended instance
        //queryResultSuspended.Count
    
       //Loop the suspended message instance details
        foreach (System.Management.ManagementObject obj in queryResultSuspended)
        {
            string sHostNameForSuspendedInstance = obj["HostName"].ToString();
            string sMessageInstanceID = obj["InstanceID"].ToString(); 
        }
    
    
    
        queryWMIActive = new System.Management.ObjectQuery("SELECT * FROM MSBTS_ServiceInstance where ServiceStatus=2");
        searcher = new System.Management.ManagementObjectSearcher(oMs, queryWMIActive);
        queryResultActive = searcher.Get();
    
        //Loop the suspended message instance details
        foreach (System.Management.ManagementObject obj in queryResultActive)
        {
            //Do whatever you watnt to do with the active instance details.
        }
    
    
    }
    catch (Exception ex)
    {
        string error = ex.Message;
    }

    In the above code, ensure you give correct username and password to access the remote server. I have commented out here. Or you got to reply on using the SQL (you call a stored procedure wrapped with query like the following and call this stored procedure in your .NET code:

    SELECT
          nvcName as ApplicationName,
          DATEADD(hh,-6,dtSuspendTimeStamp) as DateSuspended, -- Subtract the appropriate hours for your timezone
          nvcAdapter as Adapter,
          nvcURI as URI,
          nvcErrorDescription as ErrorDescription
    FROM InstancesSuspended with(nolock)
    LEFT OUTER JOIN [Services]
          on InstancesSuspended.uidServiceID = [Services].uidServiceID
    LEFT OUTER JOIN Modules with(nolock)
          on Modules.nModuleID = [Services].nModuleID
    WHERE DtCreated between DATEADD(dd,-7,GETUTCDATE()) and GETUTCDATE()
    and nErrorCategory=0
    ORDER BY dtCreated desc

    Sometime when running operation commands from a remote you could facing something called “Double Hop issue”,

    If you face any issues (after ensuring you’re using the correct credentials and the issue is nothing to do with access) still if you get error like “Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.”If so, then the following article can be useful check where its been pointout this this issue could come due to “Double Hop” issue. Good explanation has been given there.


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    • Edited by M.R.Ashwin Prabhu Friday, January 23, 2015 11:02 AM
    • Marked as answer by Angie Xu Wednesday, January 28, 2015 3:07 AM
    Friday, January 23, 2015 11:00 AM

All replies

  • Is it possible to read remote server data from BizTalk .net References?--> Yes it is possible to read as long as you are running your application with valid credentials and allowed to access BizTalk Databases.

    You can use BtsCatalogExplorer Methods to read and change things in BizTalk.

    What are you trying to achieve Please provide more details?


    Greetings,HTH
    Naushad Alam

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
    alamnaushad.wordpress.com

    Thursday, January 22, 2015 1:40 PM
    Moderator
  • Well sure, but what exactly are you trying to do?  Meaning, what Business or Operational problem are you trying to address?
    Thursday, January 22, 2015 3:00 PM
    Moderator
  • Thank you, I will try to use this method and update if i face any problem in it.

    The reason I am doing this is, its a admin task to get all the suspended instance, active instance and other things reported daily and we have multiple biztalk server to automate this I am tring to automate this daily task.

    Let me know if any good example is available you you guys :)


    Regards, Sagar Kakade http://www.me-ensemblo.com

    Friday, January 23, 2015 9:40 AM
  • I don't think you can use " BtsCatalogExplorer" for get the details of message instances status like suspended or active. You got to either use WMI or SQL.

    Following code uses WMI classes in .NET to get the suspended instance details and active instance details. You can modify this code to suit your need:

    System.Management.ManagementScope oMs;
    System.Management.ObjectQuery queryWMISuspended;
    System.Management.ObjectQuery queryWMIActive;
    System.Management.ManagementObjectSearcher searcher;
    System.Management.ManagementObjectCollection queryResultSuspended;
    System.Management.ManagementObjectCollection queryResultActive;
    try
    {
        System.Management.ConnectionOptions connOption = new System.Management.ConnectionOptions();
        //connOption.Username = @"*****";
        //connOption.Password = "*****";
        connOption.Impersonation = System.Management.ImpersonationLevel.Impersonate;
        connOption.Authentication = System.Management.AuthenticationLevel.Packet;
        connOption.EnablePrivileges = true;
    
        //Replace this with your servername
        string serverName = "localhost";
       
        oMs = new System.Management.ManagementScope(@"\\" + serverName + @"\root\MicrosoftBizTalkServer", connOption);
        //oMs = new System.Management.ManagementScope(@"\\" + serverName + @"\root\cimv2", connOption);
    
        queryWMISuspended = new System.Management.ObjectQuery("SELECT * FROM MSBTS_ServiceInstance where ServiceStatus=4 AND ServiceClass = 4");
        searcher = new System.Management.ManagementObjectSearcher(oMs, queryWMISuspended);
        queryResultSuspended = searcher.Get();
    
        //Following code will give you the count of suspended instance
        //queryResultSuspended.Count
    
       //Loop the suspended message instance details
        foreach (System.Management.ManagementObject obj in queryResultSuspended)
        {
            string sHostNameForSuspendedInstance = obj["HostName"].ToString();
            string sMessageInstanceID = obj["InstanceID"].ToString(); 
        }
    
    
    
        queryWMIActive = new System.Management.ObjectQuery("SELECT * FROM MSBTS_ServiceInstance where ServiceStatus=2");
        searcher = new System.Management.ManagementObjectSearcher(oMs, queryWMIActive);
        queryResultActive = searcher.Get();
    
        //Loop the suspended message instance details
        foreach (System.Management.ManagementObject obj in queryResultActive)
        {
            //Do whatever you watnt to do with the active instance details.
        }
    
    
    }
    catch (Exception ex)
    {
        string error = ex.Message;
    }

    In the above code, ensure you give correct username and password to access the remote server. I have commented out here. Or you got to reply on using the SQL (you call a stored procedure wrapped with query like the following and call this stored procedure in your .NET code:

    SELECT
          nvcName as ApplicationName,
          DATEADD(hh,-6,dtSuspendTimeStamp) as DateSuspended, -- Subtract the appropriate hours for your timezone
          nvcAdapter as Adapter,
          nvcURI as URI,
          nvcErrorDescription as ErrorDescription
    FROM InstancesSuspended with(nolock)
    LEFT OUTER JOIN [Services]
          on InstancesSuspended.uidServiceID = [Services].uidServiceID
    LEFT OUTER JOIN Modules with(nolock)
          on Modules.nModuleID = [Services].nModuleID
    WHERE DtCreated between DATEADD(dd,-7,GETUTCDATE()) and GETUTCDATE()
    and nErrorCategory=0
    ORDER BY dtCreated desc

    Sometime when running operation commands from a remote you could facing something called “Double Hop issue”,

    If you face any issues (after ensuring you’re using the correct credentials and the issue is nothing to do with access) still if you get error like “Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.”If so, then the following article can be useful check where its been pointout this this issue could come due to “Double Hop” issue. Good explanation has been given there.


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    • Edited by M.R.Ashwin Prabhu Friday, January 23, 2015 11:02 AM
    • Marked as answer by Angie Xu Wednesday, January 28, 2015 3:07 AM
    Friday, January 23, 2015 11:00 AM
  • For clarity, you will need to use WMI.  Instance data is not available through ExplorerOM.

    A programmatic management solution frequently requires a combination of:

    WMI - https://msdn.microsoft.com/en-us/library/aa547120.aspx

    ExplorerOM - https://msdn.microsoft.com/en-us/library/Microsoft.BizTalk.ExplorerOM.aspx

    BtsCatalogExplorer is part of ExplorerOM.

    Friday, January 23, 2015 11:11 AM
    Moderator
  • The reason I am doing this is, its a admin task to get all the suspended instance, active instance and other things reported daily and we have multiple biztalk server to automate this I am tring to automate this daily task.

    If I understand your requirement correctly, I would advice you can also consider usingBHM plug-in for the administration and monitoring purpose.

    Benefits:

    • Monitoring tool which can be integrated with BizTalk Administration Console.
    • Free plug-In provided by Microsoft which can be installed on BizTalk server 2010 and 2013. No licensing required until BizTalk Server properly licensed.   
    • This feature allows you to monitor multiple BizTalk platforms like Production and Pre-Production BizTalk roups from single MMC.
    • Can add custom queries as per the business requirement.

    Types of custom queries include:

    ü  WMI query

    ü  VB Script

    ü  PowerShell query

    ü  Batch file (.bat)

    ü  CMD

    •  BHM provides you a way to create a scheduled task to automate a periodic collection of BHM report.
    • BHM provides a large number of performance counters to monitor like the state of the BizTalk databases, the BizTalk queues, the messaging and XLANG performances, the throttling states, the adapters performances etc…

    Standalone version of BHM can be downloaded from Microsoft Download Center here: BizTalk Health Monitor.

    Refer: Overview of BizTalk Health Monitor (BHM)

    BizTalk Health Monitor v2 released!

    Rachit

    Please mark as answer or vote as helpful if my reply does

    Friday, January 23, 2015 12:47 PM
    Moderator