Thursday, May 5, 2011

TFS OData Services as data source for SSRS reports

In April Microsoft release a beta of TFS OData Services , enabling a simply way to query and update tfs using http Url’s and atom xml data f, even from non-Windows platforms. This is good news for everyone who wants to extend tfs to mobile devices, but I saw an alternative use for it.

Looking for a SSRS data source
If you want to create reports containing details of work item, a story card report for example, you don’t really have a good data source to base your report on. The TFS Warehouse doesn’t offer vital fields like description, history and many other fields of importance. So far the best option I’ve found is to use Ewald Hofman’s solution in this post Although it’s a proven working solution it requires both customizations and deployment of a web services . If TFS OData services will be a part of TFS installation it could be the answer I’ve been looking for.

Installing TFS OData services
To test the new TFS OData services, I started installing it on one of our lab servers. Quite quickly it became obvious that TFS OData install is not install that simply installs the TFS OData Services on a Server. It installs a complete development environment for developers who wants to build mobile TFS applications. To get it installed I switch to a lab devbox and installed all the tools required by the install. Once installed I needed to point the TFS OData services to a tfs server, this was no problem. One thing that caused me some problems was to handle the certificates.

OData as datasource in SSRS
As Microsoft has been pushing OData quite a bit, I was expecting it to be fairly easy to consume OData services in SSRS. Sadly I was surprised to find out that SSRS can generate an OData feed, but have no guidance how to consume OData as a data sources. After quite some time searching and asking around my colleagues I found a solution. SSRS have an XML data source, and you can specify an url as connection string. You can also specify Query parameters and how to translate the returning xml using the Query in SSRS. The following XML translates the OData response to fields in SSRS:
<ElementPath IgnoreNamespaces="true">

OData & SSRS - Possible but not practical
So it is possible to consume OData services in SSRS, but it’s not really practical as you specify the URL in the data source. OData uses the URL as the query specification, forcing you to have one data source for each query you intend to use. It might be possible to fix this or write an custom data source adapter for OData, using SSRS extension model.

Beta 1 shortcomings
As I got a data source and a query in SSRS, I started to create a simple story card report. Quite soon I run into trouble. Some parts of the URI’s used for accessing queries is less natural, like /ColletionName/Queries('b3844370-e517-471d-a55c-d45f9bf7716d')/WorkItems This formats with guids as identifiers for queries, instead of query name, might work if coding against it, but for manually doing reporting it’s not a great experience.
The next problem is that the beta 1 of TFS OData returns a predefined subset of a work item, regardless of the work item definition, or the query specification. This is a show stopper, at least as a SSRS data source.

If you want to create reports containing details of work item the best option is still Ewald Hofman’s solution to create an web service to execute Work Item Queries using the TFS API. TFS OData has to develop and grow a bit before it can be used as a data source, on the other hand it’s only a beta 1 yet. The potential is there in the OData format and if its developed and delivered as a part of TFS it could be used as a standardized data source for TFS data.