Create a WebAPI Data Processing Extension for Report Viewer

To create a WebAPI data processing extension for the Bold Reports® JavaScript Report Viewer, implement the IDataExtension interface in a class and register the extension in the application configuration.

How do I configure the dependent assemblies?

To configure the dependent assemblies for the WebAPI data processing extension, add the BoldReports.Web reference and the WebAPI reference to the application. The references provide the extension support for the WebAPI data source in the Report Viewer.

If you create separate libraries for the data processing extensions, add the BoldReports.Web and WebAPI references to your class library.

How do I implement the data processing extension?

To implement the WebAPI data processing extension, implement the IDataExtension interface in your data processing extension class. The Report Viewer invokes the IDataExtension members.

namespace BoldReports.DataExtensions.WebAPI
{
    public class WebAPIDataExtension : BoldReports.Data.IDataExtension
    {

TestConnection

The Report Viewer invokes the TestConnection member of the data processing extension for the configured data source when you test the connection during data source creation. Write the implementation in this method to test the connection of the configured data source. The following code shows the implementation for the WebAPI data processing extension.

public bool TestConnection(out string error)
{
    error = string.Empty;
    return true;
}

GetData

The Report Viewer invokes the GetData member of the data processing extension to get the data for the configured data source. Write the implementation in this method to run the data source query and return the query result.

public object GetData(out string error)
{
    try
    {
        error = string.Empty;
        this.updateQueryData(this.Command.Text);
        var settings = new JsonSerializerSettings
        {
            DateParseHandling = DateParseHandling.DateTimeOffset
        };
        return this.GetReportData(
            Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(this.InvokeServiceRequest(this.ConnectionProperties.ConnectionString).ToString(), settings));
    }
    catch (Exception ex)
    {
        error = ex.Message;
        return null;
    }
}

How do I deploy the data processing extension in the Report Viewer?

To deploy the WebAPI data processing extension in the JavaScript Report Viewer, register the extension in the application configuration, as described in the following sections.

How do I configure the data processing extension?

To configure the data processing extension with the Report Viewer, add the extension information to the application configuration in the following format.

  <configSections>
      <section name="ReportingExtensions" type="BoldReports.Configuration.Extensions, BoldReports.Web" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>

  <ReportingExtensions>
    <DataExtensions>
<Extension Name="WebAPI" Assembly="BoldReports.DataExtensions.WebAPI" Type="BoldReports.DataExtensions.WebAPI.WebAPIDataExtension"/>
    </DataExtensions>
  </ReportingExtensions>

Add the dependent assemblies to the application, or make sure they are in the application location.

How do I configure an extension built as a class library?

If you built the WebAPI data extension as a class library, use the following format in the Report Viewer application configuration.

  <configSections>
      <section name="ReportingExtensions" type="BoldReports.Configuration.Extensions, BoldReports.Web" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>

  <ReportingExtensions>
   <DataExtension>
<Extension Name="WebAPI" Assembly="BoldReports.DataExtensions.WebAPI" Type="BoldReports.DataExtensions.WebAPI.WebAPIDataExtension"/>
    </DataExtension>
  </ReportingExtensions>

Add the data processing extension assemblies and dependent assemblies to the application, or make sure they are in the application location.

Download the WebAPI Data Processing Extensions sample