Table of Contents

Class RestDataProvider

Namespace
combit.Reporting.DataProviders
Assembly
combit.ListLabel31.CrossPlatform.dll

Provides a data provider implementation for RESTful web services returning XML or JSON data.

public class RestDataProvider : IDataProvider, ISupportsLogger, IDisposable
Inheritance
RestDataProvider
Implements
Inherited Members

Examples

The following example demonstrates how to use the RestDataProvider to export a report to PDF:

// Example 1: Load JSON from a public REST API
RestDataProvider provider = new RestDataProvider("https://api.example.com/customers.json");

// Optional: Set custom root table name for JSON
provider.RootTableName = "Customers";

// Create a ListLabel reporting engine instance and assign the provider as the data source.
using ListLabel listLabel = new ListLabel();
listLabel.DataSource = provider;

// Configure export settings to generate a PDF.
ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, exportFilePath, projectFilePath);
exportConfiguration.ShowResult = true;

// Export the report to PDF.
listLabel.Export(exportConfiguration);

// Example 2: REST API with basic authentication
RestDataProvider authProvider = new RestDataProvider(
    "https://api.example.com/secure/data.json",
    "username",
    "password",
    "");

// Example 3: REST API with custom headers (API key)
RestDataProvider apiProvider = new RestDataProvider("https://api.example.com/data.json");
apiProvider.Headers.Add("Authorization", "Bearer your_token_here");
apiProvider.Headers.Add("X-API-Key", "your_api_key");
apiProvider.ConnectionTimeout = 30; // 30 seconds

// Example 4: OAuth 2.0 authentication with token refresh
RestDataProvider oauthProvider = new RestDataProvider("https://api.example.com/data.json");

oauthProvider.OAuth2Connection = new OAuth2Connection
{
    AccessTokenUrl = "https://auth.example.com/token",
    RefreshToken = "your_refresh_token",
    ClientId = "your_client_id",
    ClientSecret = "your_client_secret",
    Scope = "api.read"
};

// Handle token refresh events to update stored tokens
oauthProvider.OAuth2TokenRefreshed += (sender, e) =>
{
    Console.WriteLine($"New access token: {e.AccessToken}");
    if (e.RefreshToken != null)
    {
        Console.WriteLine($"New refresh token: {e.RefreshToken}");
        // Save the new refresh token to your configuration
    }
};

// Example 5: Load XML from a file share with authentication
RestDataProvider fileProvider = new RestDataProvider(
    @"file://\\server\share\data.xml",
    @"DOMAIN\username",
    "password",
    "DOMAIN");

// Example 6: Dynamic URL with parameters
RestDataProvider dynamicProvider = new RestDataProvider(
    "https://api.example.com/data.json?date={{ReportDate=2024-01-01}}");
dynamicProvider.RootTableName = "DailyReport";

Remarks

The RestDataProvider class implements IDataProvider, ISupportsLogger, combit.Reporting.DataProviders.ISupportsParameters, and IDisposable to enable flexible connectivity to REST APIs and web services. The provider downloads content from a URL or file path and automatically detects the format (XML or JSON), creating an appropriate underlying data provider (XmlDataProvider or JsonDataProvider). It supports multiple authentication methods including basic authentication with username/password/domain, OAuth 2.0 with refresh tokens, and custom HTTP headers. Network credentials can be configured for authenticated file access (UNC paths). Parameter binding allows dynamic URLs that change based on report parameters. OAuth 2.0 token refresh is handled automatically with event notification when tokens are updated. The provider is ideal for consuming data from REST APIs, web services, or file servers, providing a simple bridge between web-based data sources and List & Label reporting. Custom JSON root table names can be specified for better semantic meaning.

Constructors

RestDataProvider(string)

Initializes a new instance of the RestDataProvider class with the specified URL.

public RestDataProvider(string url)

Parameters

url string

The URL of the REST endpoint.

RestDataProvider(string, string, string, string)

Initializes a new instance of the RestDataProvider class with the specified URL and credentials.

public RestDataProvider(string url, string username, string password, string domain)

Parameters

url string

The URL of the REST endpoint.

username string

The user name for authentication.

password string

The password for authentication.

domain string

The domain for authentication.

Properties

ConnectionTimeout

Gets or sets the connection timeout (in seconds) for REST requests.

public int ConnectionTimeout { get; set; }

Property Value

int

Headers

Gets the collection of HTTP headers that will be used for the REST request.

public HttpRequestHeaders Headers { get; }

Property Value

HttpRequestHeaders

OAuth2Connection

Gets or sets the OAuth 2.0 connection details used for making authenticated web requests to the Url.

public OAuth2Connection OAuth2Connection { get; set; }

Property Value

OAuth2Connection

RootTableName

Gets or sets the root table name that should be used by the underlying JSON data provider, if it is not null or an empty string. Only applicable for JSON results.

public string RootTableName { get; set; }

Property Value

string

Url

Gets or sets the URL used for the REST request. When set, the provider resets its initialization state and marks all current tables as volatile.

public string Url { get; protected set; }

Property Value

string

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the RestDataProvider and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

ResolveDataProvider(string)

Resolves the downloaded content to a specific data provider instance. The base implementation detects XML or JSON content and returns an XmlDataProvider or JsonDataProvider accordingly.

protected virtual IDataProvider ResolveDataProvider(string content)

Parameters

content string

The downloaded plain text content from the specified Url.

Returns

IDataProvider

An instance of IDataProvider corresponding to the content.

SetLogger(ILlLogger, bool)

Sets the logger for the object.

public void SetLogger(ILlLogger logger, bool overrideExisting)

Parameters

logger ILlLogger

The logger to set.

overrideExisting bool

Specifies whether to override an existing logger.

Events

OAuth2TokenRefreshed

Occurs when OAuth 2.0 tokens are refreshed. Use this event to update the stored refresh token with the new value.

public event EventHandler<OAuth2TokenRefreshedEventArgs> OAuth2TokenRefreshed

Event Type

EventHandler<OAuth2TokenRefreshedEventArgs>