Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Querying BAM Data using BAM’s Web Services

Kevin Morillo

Our BizTalk Practice has recently embarked on the endeavor of creating a tracking portal for one of our new BizTalk solution accelerators.  One of the initial steps for me was to devise a proof of concept for querying the BAM Database using the two included web services with BAM, BAMManagementService and BAMQueryService.  Microsoft does not officially support directly utilizing the two web services, limiting their official use to the BAM Portal exclusively.

If however, you find yourself in need of querying BAM data using the predefined web services, you can use the following:

The first step required before utilizing the web services is to add them as web services in your visual studio project.

Add a web reference and point to your BAM Management Service URL, the default being

http://localhost/BAM/BamManagementService/BamManagementService.asmx.

image

image

Then do the same for BAMQueryService pointing to your BAMQueryService URL, the default being

http://localhost/BAM/BAMQueryService/BAMQueryService.asmx

The following code snippet will call the BAMQueryService for the specified view ‘vw_ProcessTracking’, and activity.  The cd 2D array will then contain all of the tracking data present in BAM for that view.

1 DataTable dt = new DataTable(BamTable); 2  using (var queryService = new BAMQueryWebService.BamQueryService()) 3 { 4 // The client must be a member of the BAM Portal Users group. 5   queryService.Credentials = System.Net.CredentialCache.DefaultCredentials; 6 7 var query = new Tallan.BizTalk.BAM.Utility.BAMQueryWebService.InstanceQuery(); 8 query.SelectClauses = GetViewColumns(vw_ProcessTracking).ToArray(); 9 10 Column[][] cd = queryService.GetInstanceData(vw_ProcessTracking, ProcessTracking, query, 15); 11 }

The GetViewColumns method utilizes the BAMManagementService to get a list of the columns present in the specified view.

1 public List<String> GetViewColumn(String viewName) 2 { 3 // Create a web service proxy object. 4   var managementService = new BamManagementService(); 5 6 // must be a member of the BAM Portal Users group. 7   managementService.Credentials = System.Net.CredentialCache.DefaultCredentials; 8 9 // retrieve BAM view definition XML. 10   var bamXML = managementService.GetViewDetailsAsXml(viewName); 11 12 //Get enumeration of columns in the view 13   var xmlDoc = new XmlDocument(); 14 xmlDoc.LoadXml(bamXML); 15 var ns = new XmlNamespaceManager(xmlDoc.NameTable); 16 ns.AddNamespace(bam, http://schemas.microsoft.com/BizTalkServer/2004/10/BAM); 17 var node = xmlDoc.SelectSingleNode(string.Format(//bam:View[@Name='{0}’], viewName), ns); 18 XmlNodeList columnNodeList = node.SelectNodes(./bam:ActivityView/*, ns); 19 20 return columnNodeList.OfType<XmlNode>().Select(x => x.Attributes[Name].Value).ToList(); 21 } 22  

Note:

If you receive the following error, as I originally did, when executing the BAMQueryService web service call, make sure to verify the view name argument of the ‘GetInstanceData’ meothod.

System.Web.Services.Protocols.SoapException: Server was unable to process request. —> Microsoft.BizTalk.Bam.Management.BamManagerException: Failed to list permissions for BAM view. —> Microsoft.BizTalk.Bam.Management.BamManagerException: The dbo.bam_vw_ProcessTracking_AllInstances view does not exist in the BAMPrimaryImport database.

The ‘GetInstanceData’ method expects the view name, activity name, query object, and an integer representing the timeout value.  The view name, above shown as ‘vw_ProcessTracking’ is the same view name that appears in the BAM Portal as can be seen below.  This is different than what may be seen on MSDN

image

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>