none
Application Name and URI extraction through wmi

    Question

  • Does anyone know how to extract BizTalk application name and URI using WMI (C#)? 

    Thanks in advance.

    Tuesday, December 23, 2014 7:26 AM

Answers

  • Hi Pratibha,

    I assume you're looking to find a way to get the URL of the send port which was consumed by BizTalk. Then you can use the following code. This code expects the send port name for which URL will be returned back.

    private string GetSendPortURL(string sSendPortName)
    {
        // connect to the local BizTalk Management database
        Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer catalog = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();
        string sSendPortURL = String.Empty;
        try
        {
            //connection string to BizTalk management database
            catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
    
            foreach (Microsoft.BizTalk.ExplorerOM.SendPort sendPort in catalog.SendPorts)
            {
                if (sendPort.Name.Trim() == sSendPortName)
                {
                    sSendPortURL = sendPort.PrimaryTransport.Address;
                }
            }
        }
        catch (Exception ex)
        {
            //Handle exception
            System.Diagnostics.EventLog.WriteEntry("AppError", ex.ToString());
            catalog.DiscardChanges();
            throw ex;
        }
        return sSendPortURL;
    }

    If its the Receive port's URL which you meant by "consumed by BizTalk", then the following code shall get you the URL of the primary receive location of the given Receive port:

    private string GetReceivePortURL(string sReceivePortName)
    {
        // connect to the local BizTalk Management database
        Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer catalog = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();
        string sReceivePortURL = String.Empty;
        try
        {
            //connection string to BizTalk management database
            catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
    
            foreach (Microsoft.BizTalk.ExplorerOM.ReceivePort receivePort in catalog.ReceivePorts)
            {
                if (receivePort.Name.Trim() == sReceivePortName)
                {
                    sReceivePortURL = receivePort.PrimaryReceiveLocation.Address;
                }
            }
        }
        catch (Exception ex)
        {
            //Handle exception
            System.Diagnostics.EventLog.WriteEntry("AppError", ex.ToString());
            catalog.DiscardChanges();
            throw ex;
        }
        return sReceivePortURL;
    }

    Or if you're looking for way to access all the URL in the BizTalk applications, then you can use the above code without the if condition, which would loop through all the existing port URLs.


    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.

    Tuesday, December 30, 2014 11:42 AM

All replies

  • Hi Prathiba,

    You can use ExplorerOM to get the application name and URI. Not WMI but also not directly querying the BTS databases. What you need to do is to add referece to  ExplorerOM (Microsoft.BizTalk.ExplorerOM.dll).

    For more information: http://msdn.microsoft.com/en-us/library/microsoft.biztalk.explorerom.sendport_members(v=BTS.10).aspx

    Sample code could be like below .

    use BizTalkMgmtDb select * from dbo.bts_application

    using Microsoft.BizTalk.ExplorerOM;
    
    
    private string GetApplicationDetails()
    {
    BtsCatalogExplorer catalog = new BtsCatalogExplorer();
    
    try
    {
    //connection string to BizTalk management database
    catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
    
    Microsoft.BizTalk.ExplorerOM.Application ApplicationNames = catalog.Applications;
    
    
    for ( int i =0 ;i<=Microsoft.BizTalk.ExplorerOM.Application ;i++)
            {
                String ApplicationNames += application.Name.ToString()+ " ,";
            }
    
    
    
    if (app == null)
    {
    throw new Exception(String.Format("Application '{0}' cannot be found.", applicationName));
    }
    	exception;
    }
    catch (Exception ex)
    {
    //Handle exception
    System.Diagnostics.EventLog.WriteEntry("MyMonitoryingApp", "Exception call stack: " + ex.ToString());
    }
    finally
    {
    if (catalog != null) { catalog.Dispose(); }
    }
    return ApplicationNames ;
    }
    

    Thanks

    Abhishek


    Tuesday, December 23, 2014 7:38 AM
  • Hi Pratibha,

    Above code will only get you the application status or application collection class not the Application NAME(S). To get name of the BizTalk application, you need to use “Name” property of ExplorerOM.Application

    You cannot get BizTalk application name using WMI. Because Application concepts was first introduced in BizTalk 2006 onwards and WMI class to access the BizTalk was introduced in BizTalk 2004 and WMI classes were not updated after that.

    But as suggested you can use ExplorerOM to access the BiZtalk application name. Following will get you the list of applications in a string. You can update it to get the specific application or list of applications as shown below.

    private string GetBTSApplicationNames()
    {
        // connect to the local BizTalk Management database
        Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer catalog = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();
        string sAppNames = String.Empty;
        try
        {
            //connection string to BizTalk management database
            catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
          
            //Loop thru the list of applications. Here I am appending it to a string, you can do as your requirment.
            foreach (Microsoft.BizTalk.ExplorerOM.Application application in catalog.Applications)
            {
                sAppNames += application.Name.ToString()+ " ,";
            }
        }
        catch (Exception ex)
        {
            //Handle exception
            System.Diagnostics.EventLog.WriteEntry("AppError", ex.ToString());
            catalog.DiscardChanges();
            throw ex;
        }
        return sAppNames;   
    }

     


    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.


    Tuesday, December 23, 2014 9:11 AM
  • Another way around both by SQL and Explorer.

    You can return a Data Table with all Application ID

    public DataTable GetBizTalkApplication()
    {
    BtsCatalogExplorer catalog = new BtsCatalogExplorer();
    DataTable apptbl = CreateAppTBL();
     //connection string to BizTalk management database
     catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
    DataRow dr;
    foreach (Microsoft.BizTalk.ExplorerOM.Application app in catalog.Applications)
    {
    
    dr = apptbl.NewRow();
    dr["AppName"] = app.Name;
    dr["AppDesc"] = app.Description;
    dr["AppStatus"] = app.Status;          
    apptbl.Rows.Add(dr);
     }
    return apptbl;
    }

    By SQL It will be easy again

    USE BizTalkMgmtDb
    SELECT	app.nvcName AS [Application],
    	ass.nvcName AS [Assembly],
    	orc.nvcName AS [Orchestration],
    	orc.nOrchestrationStatus AS [Status],
    	orp.nvcName AS [Orchestration Port],
    	pt.nvcName AS [Port Type],
    	pto.nvcName AS [Port Type Operation],
    	rp.nvcName AS [Receive Port],
    	rl.Name AS [Receive Location],
    	rppl.Name AS [Receive Pipeline],
    	sp.nvcName AS [Send Port],
    	sppl.Name AS [Send Pipeline],
    	spg.nvcName AS [Send Port Group]
    FROM bts_application app WITH(NOLOCK)
    LEFT OUTER JOIN bts_assembly ass WITH(NOLOCK) ON app.nID = ass.nApplicationId
    LEFT OUTER JOIN bts_orchestration orc WITH(NOLOCK) ON ass.nID = orc.nAssemblyId
    LEFT OUTER JOIN bts_orchestration_port orp WITH(NOLOCK) ON orc.nID = orp.nOrchestrationId
    LEFT OUTER JOIN bts_porttype pt WITH(NOLOCK) ON orp.nPortTypeID = pt.nID
    LEFT OUTER JOIN bts_porttype_operation pto WITH(NOLOCK) ON pt.nID = pto.nPortTypeID
    LEFT OUTER JOIN bts_orchestration_port_binding opp WITH(NOLOCK) ON orp.nID = opp.nOrcPortID
    LEFT OUTER JOIN bts_receiveport rp WITH(NOLOCK) ON opp.nReceivePortID = rp.nID
    LEFT OUTER JOIN adm_ReceiveLocation rl WITH(NOLOCK) ON rp.nID = rl.receiveportId
    LEFT OUTER JOIN bts_pipeline rppl WITH(NOLOCK) ON rl.ReceivePipelineId = rppl.Id
    LEFT OUTER JOIN bts_sendport sp WITH(NOLOCK) ON opp.nSendPortID = sp.nID
    LEFT OUTER JOIN bts_pipeline sppl WITH(NOLOCK) ON sp.nSendPipelineID = sppl.Id
    LEFT OUTER JOIN bts_sendportgroup spg WITH(NOLOCK) ON opp.nSpgID = spg.nID
    WHERE orc.nvcName IS NOT NULL
    ORDER BY 1,2,3
    
    -- Status
    -- 1 = Unenlisted
    -- 2 = Stopped
    -- 3 = Started

    Thanks

    Abhishek

    Tuesday, December 23, 2014 7:13 PM
  • Anything for retrieving URI?
    Wednesday, December 24, 2014 5:48 AM
  • Anything for retrieving URI?

    The SQL scripts in my above post will give you the URI properties as well which is being associated with host instance .

    Thanks

    Abhishek

    Wednesday, December 24, 2014 6:49 AM
  • Anything for retrieving URI?

    The SQL scripts in my above post will give you the URI properties as well which is being associated with host instance .

    Thanks

    Abhishek

    I guess SQL scripts won't work with WMI programming. Is there any other way of getting URI?
    Wednesday, December 24, 2014 8:37 AM
  • you can get uri like below.  You can manage the process as per your requirement.

    Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer catalog = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();

    foreach (Microsoft.BizTalk.ExplorerOM.Application application in catalog.Applications) { foreach (Microsoft.BizTalk.ExplorerOM.ReceivePort recport in application.ReceivePorts) { foreach (Microsoft.BizTalk.ExplorerOM.ReceiveLocation recloc in recport.ReceiveLocations) { System.Console.Write(recloc.Address); } } foreach (Microsoft.BizTalk.ExplorerOM.SendPort sendport in application.SendPorts) { System.Console.Write(sendport.PrimaryTransport.Address); } }



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



    Wednesday, December 24, 2014 12:37 PM
  • What do you mean by URI. URL for which receive location and send port configured to. If you do you want to get all the URL in your BizTalk application? What is your exact requirement?



    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.

    Wednesday, December 24, 2014 12:43 PM
  • You can try this

    public DataTable GetBizTalkApplication() { BtsCatalogExplorer catalog = new BtsCatalogExplorer(); DataTable URITble = CreateAppTBL(); //connection string to BizTalk management database catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; DataRow dr; foreach (Microsoft.BizTalk.ExplorerOM.Application app in catalog.Applications) { foreach (Microsoft.BizTalk.ExplorerOM.ReceivePort recport in application.ReceivePorts) { foreach (Microsoft.BizTalk.ExplorerOM.ReceiveLocation recloc in recport.ReceiveLocations) dr = URITble .NewRow(); dr["AppName"] = app.Name; dr["AppDesc"] = app.Description; apptbl.Rows.Add(dr); } return URITble; }

    }

    Thanks

    Abhishek

    Wednesday, December 24, 2014 3:05 PM
  • What do you mean by URI. URL for which receive location and send port configured to. If you do you want to get all the URL in your BizTalk application? What is your exact requirement?



    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.

     I want to retrieve the URI provided by SAP to Biztalk (which biztalk consume).
    Tuesday, December 30, 2014 10:02 AM
  • For Getting URI details you need to query send Port and receive location in BIzTalk

     foreach (Microsoft.BizTalk.ExplorerOM.ReceivePort receiveportaddres in application.ReceivePorts)
                    {
                       foreach (Microsoft.BizTalk.ExplorerOM.ReceiveLocation reclocationURI in receiveportaddres.ReceiveLocations)
                        {
                            System.Console.Write(reclocationURI.Address);
                        }
                    }
    
                    foreach (Microsoft.BizTalk.ExplorerOM.SendPort sendportURI in application.SendPorts)
                    {
                        System.Console.Write(sendportURI.PrimaryTransport.Address);
                    }
    

    Thanks

    Abhishek




    Tuesday, December 30, 2014 10:27 AM
  • Hi Pratibha,

    I assume you're looking to find a way to get the URL of the send port which was consumed by BizTalk. Then you can use the following code. This code expects the send port name for which URL will be returned back.

    private string GetSendPortURL(string sSendPortName)
    {
        // connect to the local BizTalk Management database
        Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer catalog = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();
        string sSendPortURL = String.Empty;
        try
        {
            //connection string to BizTalk management database
            catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
    
            foreach (Microsoft.BizTalk.ExplorerOM.SendPort sendPort in catalog.SendPorts)
            {
                if (sendPort.Name.Trim() == sSendPortName)
                {
                    sSendPortURL = sendPort.PrimaryTransport.Address;
                }
            }
        }
        catch (Exception ex)
        {
            //Handle exception
            System.Diagnostics.EventLog.WriteEntry("AppError", ex.ToString());
            catalog.DiscardChanges();
            throw ex;
        }
        return sSendPortURL;
    }

    If its the Receive port's URL which you meant by "consumed by BizTalk", then the following code shall get you the URL of the primary receive location of the given Receive port:

    private string GetReceivePortURL(string sReceivePortName)
    {
        // connect to the local BizTalk Management database
        Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer catalog = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();
        string sReceivePortURL = String.Empty;
        try
        {
            //connection string to BizTalk management database
            catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
    
            foreach (Microsoft.BizTalk.ExplorerOM.ReceivePort receivePort in catalog.ReceivePorts)
            {
                if (receivePort.Name.Trim() == sReceivePortName)
                {
                    sReceivePortURL = receivePort.PrimaryReceiveLocation.Address;
                }
            }
        }
        catch (Exception ex)
        {
            //Handle exception
            System.Diagnostics.EventLog.WriteEntry("AppError", ex.ToString());
            catalog.DiscardChanges();
            throw ex;
        }
        return sReceivePortURL;
    }

    Or if you're looking for way to access all the URL in the BizTalk applications, then you can use the above code without the if condition, which would loop through all the existing port URLs.


    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.

    Tuesday, December 30, 2014 11:42 AM