How to programatically retrieve data from BAMPrimaryImport using supportable API

Eventhough there are Portal UI and Excel that would allow you to query and access BAM activity data, it seems that there are some of you who would like to programmatically access/query this data from a custom application.

In BizTalk Server Documentation, currently in its 2006 pre-released version, you will find information on the BAMManagementService API.  (Under Technical Reference | Developers Reference | BizTalk Server 2006 .Net Class Reference | Microsoft.BizTalk.Bam.Webservices.Management ). 

The BamManagementService class is what we are interested. This is a webservice API and you can also see its methods by pointing to the box where Biztalk is installed. (replace localhost with the machine name in the link below). 

https://localhost/BAM/BamManagementService/BamManagementService.asmx

For example, the above GetViewSummaryForCurrentUser would allow you to retrieve all views that the user has access.  And it would allow you to retrieve the activity names from there.  See code example in help doc for this.

Once you have retrieve the activity name, you can then connect to the database and call the views that below to the specific activity. 

Sample code from help doc (some of these are still been updated):

using WS = BamManagementService;

class Program
{
    static void Main(string[] args)
    {
        GetViewSummary();

        Console.WriteLine("Hit Enter when ready.");
        Console.ReadLine();
    }

    static void GetViewSummary()
    {
        // Create a web service proxy object.
        using (WS.BamManagementService managementService = new WS.BamManagementService())
        {
            // BAM Management Web Service requires client to be authenticated.
            // The client must be a member of the BAM Portal Users group.
            managementService.Credentials = System.Net.CredentialCache.DefaultCredentials;

            // Get the list of all BAM views available to the current user.
            WS.ViewSummaryList viewSummaryList = managementService.GetViewSummaryForCurrentUser();

            // Print the info for all views on the screen.
            foreach (WS.ViewSummary viewSummary in viewSummaryList.View)
            {
                Console.WriteLine("View: {0}", viewSummary.Name);
                // Each view is defined on one or more BAM activities.
                foreach (WS.ActivitySummary activitySummary in viewSummary.Activity)
                {
                    // The activity data can be on a different server/database if distributed
                    // BAM infrastructure is deployed.
                    Console.WriteLine("    Activity: {0} {1}",
                        activitySummary.Name,
                        activitySummary.IsRemote ? "[ Remote ]" : "");
                    Console.WriteLine("        Server: {0}", activitySummary.Server);
                    Console.WriteLine("        Database: {0}", activitySummary.Database);
                    Console.WriteLine("        BAM Portal URL: {0}", activitySummary.PortalUrl);

                    // OLAP and Real-time aggregations aggregations can be defined.
                    if (activitySummary.Aggregation != null)
                    {
                        Console.WriteLine("        Aggregations:");
                        foreach (WS.Aggregation aggregation in activitySummary.Aggregation)
                        {
                            Console.WriteLine("            Name: {0} *** Type: {1} *** Cube Name: {2}",
                                aggregation.Name,
                                aggregation.Type,
                                aggregation.CubeName);
                            if (aggregation.PivotView != null)
                            {
                                foreach (WS.PivotView pivotView in aggregation.PivotView)
                                {
                                    Console.WriteLine("                PivotView: {0}", pivotView.Name);
                                }
                            }
                        }
                    }
                }

                Console.WriteLine();
            }

            if (viewSummaryList.PartialResults)
            {
                // Distributed BAM infrastructure is deployed and one of the referenced databases
                // is not accesible.
                Console.WriteLine("One or more of the referenced databases are not available. " +
                    "The given list of views may not be complete.");
            }
        }
    }

Sample Output:

 View: SalesManagerView
    Activity: PurchaseOrder 
        Server: purchasesrv
        Database: BAMPrimaryImport
        BAM Portal URL: https://purchasesrv/BAM
        Aggregations:
            Name: POCube *** Type: OLAP *** Cube Name: POCube
            Name: POByLocation *** Type: RTA *** Cube Name: POCube
    Activity: Shipment [ Remote ]
        Server: shipsrv
        Database: BAMPrimaryImport
        BAM Portal URL: https://shipsrv/BAM
        Aggregations:
            Name: SHCube *** Type: OLAP *** Cube Name: SHCube
            Name: SHByLocation *** Type: RTA *** Cube Name: SHCube

View: SupplyManagerView
    Activity: SupplyOrder 
        Server: purchasesrv
        Database: BAMPrimaryImport
        BAM Portal URL: https://purchasesrv/BAM
        Aggregations:
            Name: SupplyCube *** Type: OLAP *** Cube Name: SupplyCube
                PivotView: SupplyCost
            Name: SupplyTimes *** Type: RTA *** Cube Name: SupplyCube
                PivotView: SupplyTimes

Hit Enter when ready.