Search results
PDF

Create a WebAPI Data Processing Extension for Report Viewer

This article explains how to create WebAPI Data Source extension with Report Viewer.

Configure dependent Assemblies

Add the BoldReports.Web reference with the application to provide the extension support for WebAPI data source. For this, add the WebAPI reference with the application to provide the Data Processing Extensions support.

If you are going to create separate libraries for the Data Processing Extensions, then you have to add the BoldReports.Web and WebAPI references with your class library.

Implementing Data Processing Extensions

The IDataExtension interface needs to be implemented with your Data Processing Extension class to provide the extension support and IDataExtension members will be invoked from the Report Viewer.

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

TestConnection

The Data Processing Extensions TestConnection member will be invoked from the Report Viewer for configured data source when Test Connection performed with Data source creation. You should write the implementation in this method to perform the connection testing of the configured data source. Implementation for WebAPI Data Processing Extension.

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

GetData

The Data Processing Extensions GetData member will be invoked from ReportViewer to get the data for the configured data source. We should write the implementation in this method to execute the data source query and return the query result with this method.

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;
    }
}

Deploy Data Processing Extensions in ReportViewer

Data Processing Extensions Configuration

To configure the prepared Data Processing Extensions with the Report Viewer, add the Data Processing Extensions information with following format in the application configuration,

  <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>

You should add the dependent assemblies with the application or it should be there in the application location.

Configuration with extension assembly

You can use the following format, if the Data Extension prepared with Class library,

  <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>

You should add the Data Processing Extensions assemblies and dependent assemblies with the application or it should be there the application location.

WebAPI Data Processing Extensions sample