Class ReportsControllerBase
Base API controller for exposing a WebAPI to the report engine.
Inheritance
Namespace: Telerik.Reporting.Services.WebApi
Assembly: Telerik.Reporting.Services.WebApi.dll
Syntax
[ReportsExceptionFilter]
public abstract class ReportsControllerBase : ApiController
Remarks
A call to the RegisterRoutes(HttpConfiguration) method must be added to the WebApiConfig.Register method so that the controller actions are accessible from the routing mechanisms of the ASP.Net WebAPI framework.
Constructors
ReportsControllerBase()
Initializes a new instance of the ReportsControllerBase class.
Declaration
protected ReportsControllerBase()
Properties
ReportServiceConfiguration
Gets or sets the configuration of the report service.
Declaration
public IReportServiceConfiguration ReportServiceConfiguration { get; set; }
Property Value
IReportServiceConfiguration
|
Remarks
When inheriting the ReportsControllerBase controller basic configuration is needed. Provide an object implementing the IReportServiceConfiguration in order to configure the report service. This should be done in the controllers' constructor using static object to preserve the configuration between requests or using dependency injection.
Examples
This example shows how to configure WebAPI service using dependency injection.
- Setup method registering the configuration object in a dependency injection container.
The example uses the Unity container.
using System.Web; using Telerik.Reporting.Services; public static class WebApiConfig { public static void RegisterDependencies(System.Web.Http.HttpConfiguration config) { var container = new Microsoft.Practices.Unity.UnityContainer(); container.RegisterInstance( typeof(Telerik.Reporting.Services.IReportServiceConfiguration), null, CreateReportServiceConfiguration(), new Microsoft.Practices.Unity.ContainerControlledLifetimeManager()); config.DependencyResolver = new UnityResolver(container); } static IReportServiceConfiguration CreateReportServiceConfiguration() { var resolver = new UriReportSourceResolver(HttpContext.Current.Server.MapPath("~/Reports")) .AddFallbackResolver(new TypeReportSourceResolver()); return new ReportServiceConfiguration { HostAppId = "Application1", ReportSourceResolver = resolver, Storage = new Telerik.Reporting.Cache.File.FileStorage(), // Storage = new Telerik.Reporting.Cache.StackExchangeRedis.RedisStorage(StackExchange.Redis.ConnectionMultiplexer.Connect("localhost:10001")), // Storage = new Telerik.Reporting.Cache.MsSqlServerStorage(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=RSStorage;Integrated Security=SSPI"), }; } }
Example based on the article Dependency Injection in ASP.NET Web API 2Public NotInheritable Class WebApiConfig Private Sub New() End Sub Public Shared Sub RegisterDependencies(config As System.Web.Http.HttpConfiguration) Dim container = New Microsoft.Practices.Unity.UnityContainer() container.RegisterInstance( GetType(IReportServiceConfiguration), Nothing, CreateReportServiceConfiguration(), New Microsoft.Practices.Unity.ContainerControlledLifetimeManager()) config.DependencyResolver = New UnityResolver(container) End Sub Private Shared Function CreateReportServiceConfiguration() As IReportServiceConfiguration Dim resolver = New UriReportSourceResolver( HttpContext.Current.Server.MapPath("~/Reports")) _ .AddFallbackResolver(New TypeReportSourceResolver()) Dim reportServiceConfiguration As New ReportServiceConfiguration() reportServiceConfiguration.HostAppId = "Application1" reportServiceConfiguration.ReportSourceResolver = resolver reportServiceConfiguration.Storage = New Telerik.Reporting.Cache.File.FileStorage() 'reportServiceConfiguration.Storage = New Telerik.Reporting.Cache.StackExchangeRedis.RedisStorage(StackExchange.Redis.ConnectionMultiplexer.Connect("localhost:10001")) 'reportServiceConfiguration.Storage = New Telerik.Reporting.Cache.MSSqlServerStorage("Data Source=(local)\SQLEXPRESS;Initial Catalog=RSStorage;Integrated Security=SSPI") Return reportServiceConfiguration End Function End Class
- ReportsController implementation
public class ReportsController : Telerik.Reporting.Services.WebApi.ReportsControllerBase { public ReportsController(ReportServiceConfiguration configuration) { this.ReportServiceConfiguration = configuration; } }
Public Class ReportsController Inherits WebApi.ReportsControllerBase Public Sub New(configuration As ReportServiceConfiguration) Me.ReportServiceConfiguration = configuration End Sub End Class
- Invoke the setup in the Application_Start method.
public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { WebApiConfig.RegisterDependencies(System.Web.Http.GlobalConfiguration.Configuration); //... } }
Public Class MvcApplication Inherits System.Web.HttpApplication Protected Sub Application_Start() WebApiConfig.RegisterDependencies(System.Web.Http.GlobalConfiguration.Configuration) '... End Sub End Class
See Also
Methods
CreateCache()
Creates an ICache implementation instance that will be used for internal storage from the service.
Declaration
[Obsolete("CreateCache method is now obsolete. Please provide service setup using the Telerik.Reporting.Services.WebApi.ReportsControllerBase.ReportServiceConfiguration property.")]
protected virtual ICache CreateCache()
Returns
ICache
An instance of cache that will be used from the controller in order to preserve its cache/state. |
Remarks
Override this method in order to create the cache instance. May be one of the built-in caching implementations or a custom implementation. To use one of the built-in caching implementations use the CacheFactory class.
See Also
CreateDocument(String, String, CreateDocumentArgs)
Creates new document using specific format and format settings.
Declaration
public virtual HttpResponseMessage CreateDocument(string clientID, string instanceID, CreateDocumentArgs args)
Parameters
System.String
clientID
The clientID in which session the document is created. |
System.String
instanceID
The report instance used for the document. |
CreateDocumentArgs
args
Arguments containing the document format and settings. |
Returns
System.Net.Http.HttpResponseMessage
|
CreateErrorResponse(HttpStatusCode, String)
Creates error response to be sent to the client
Declaration
protected HttpResponseMessage CreateErrorResponse(HttpStatusCode statusCode, string message)
Parameters
System.Net.HttpStatusCode
statusCode
The response code. |
System.String
message
The error message. |
Returns
System.Net.Http.HttpResponseMessage
The HttpResponse containing the error message. |
CreateInstance(String, ClientReportSource)
Creates a new report instance in a client session.
Declaration
public virtual HttpResponseMessage CreateInstance(string clientID, ClientReportSource reportSource)
Parameters
System.String
clientID
The clientID for which the instance is created. |
ClientReportSource
reportSource
The report source which defines the report instance. |
Returns
System.Net.Http.HttpResponseMessage
|
CreateMailMessage(SendDocumentArgs, DocumentData)
Creates the mail message that will be used in SendDocument
Declaration
protected virtual MailMessage CreateMailMessage(SendDocumentArgs args, DocumentData result)
Parameters
SendDocumentArgs
args
The args to use in the mail message |
DocumentData
result
The document to attach to the mail message |
Returns
System.Net.Mail.MailMessage
Mail message |
CreateReportResolver()
Creates an IReportResolver implementation instance that will be used for report resolving from the service.
Declaration
[Obsolete("CreateReportResolver method is now obsolete. Please provide service setup using the Telerik.Reporting.Services.WebApi.ReportsControllerBase.ReportServiceConfiguration property.")]
protected virtual IReportResolver CreateReportResolver()
Returns
IReportResolver
IReportResolver instance. |
Remarks
Override this method in order to create the report resolver instance. May be one of the built-in report resolvers or a custom implementation resolver. Built-in resolvers may be chained.
See Also
CreateStorage()
Creates an IStorage implementation instance that will be used for internal storage from the service.
Declaration
[Obsolete("CreateStorage method is now obsolete. Please provide service setup using the Telerik.Reporting.Services.WebApi.ReportsControllerBase.ReportServiceConfiguration property.")]
protected virtual IStorage CreateStorage()
Returns
IStorage
An instance of storage that will be used from the controller in order to preserve its cache/state. |
Remarks
Override this method in order to create the storage instance. May be one of the built-in storage implementations or a custom implementation. MsSqlServerStorage RedisStorage
See Also
DeleteDocument(String, String, String)
Deletes concrete document by its ID.
Declaration
public virtual HttpResponseMessage DeleteDocument(string clientID, string instanceID, string documentID)
Parameters
System.String
clientID
The client session ID which contains the deleted document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the deleted document. |
Returns
System.Net.Http.HttpResponseMessage
|
DeleteInstance(String, String)
Deletes a report instance in a client session
Declaration
public virtual HttpResponseMessage DeleteInstance(string clientID, string instanceID)
Parameters
System.String
clientID
The clientID for which the instance is deleted. |
System.String
instanceID
The instanceID that is deleted. |
Returns
System.Net.Http.HttpResponseMessage
|
ExecuteInteractiveAction(String, String, String, String)
Executes an interactive action that should be applied on the server.
Declaration
public virtual HttpResponseMessage ExecuteInteractiveAction(string clientID, string instanceID, string documentID, string actionID)
Parameters
System.String
clientID
The client session ID which contains the document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the affected document. |
System.String
actionID
The ID of the executed action. |
Returns
System.Net.Http.HttpResponseMessage
|
GetClientsSessionTimeoutSeconds()
Gets the ClientSessionTimeout
Declaration
public virtual HttpResponseMessage GetClientsSessionTimeoutSeconds()
Returns
System.Net.Http.HttpResponseMessage
The client session timeout in seconds |
GetDocument(String, String, String)
Gets the document for a single-stream document formats.
Declaration
public virtual HttpResponseMessage GetDocument(string clientID, string instanceID, string documentID)
Parameters
System.String
clientID
The client session ID which contains the document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the document. |
Returns
System.Net.Http.HttpResponseMessage
|
GetDocumentFormats()
Gets the available document formats.
Declaration
public virtual HttpResponseMessage GetDocumentFormats()
Returns
System.Net.Http.HttpResponseMessage
|
GetDocumentInfo(String, String, String)
Gets info for a requested document.
Declaration
public virtual HttpResponseMessage GetDocumentInfo(string clientID, string instanceID, string documentID)
Parameters
System.String
clientID
The client session ID which contains the document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the document. |
Returns
System.Net.Http.HttpResponseMessage
|
GetPage(String, String, String, Int32)
Gets a page from a document in a multi-stream document format.
Declaration
public virtual HttpResponseMessage GetPage(string clientID, string instanceID, string documentID, int pageNumber)
Parameters
System.String
clientID
The client session ID which contains the document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the document. |
System.Int32
pageNumber
The number of the requested page (1-based). |
Returns
System.Net.Http.HttpResponseMessage
|
GetPageSettings(String, ClientReportSource)
Gets the report page settings for a concrete client and report source.
Declaration
public virtual HttpResponseMessage GetPageSettings(string clientID, ClientReportSource reportSource)
Parameters
System.String
clientID
The clientID for which the page settings are retrieved. |
ClientReportSource
reportSource
The report source for which the page settings are retrieved. |
Returns
System.Net.Http.HttpResponseMessage
|
GetParameters(String, ClientReportSource)
Gets the report parameters for a concrete client and report source.
Declaration
public virtual HttpResponseMessage GetParameters(string clientID, ClientReportSource reportSource)
Parameters
System.String
clientID
The clientID for which the parameters are retrieved. |
ClientReportSource
reportSource
The report source for which the parameters are retrieved. |
Returns
System.Net.Http.HttpResponseMessage
|
GetReportInstanceKey(String)
Utility method. Resolves an instance ID to a report key.
Declaration
protected ReportInstanceKey GetReportInstanceKey(string instanceID)
Parameters
System.String
instanceID
|
Returns
ReportInstanceKey
ReportInstanceKey if available, otherwise null. |
GetResource(String, String)
Gets an embedded report viewer resource.
Declaration
public virtual HttpResponseMessage GetResource(string folder, string resourceName)
Parameters
System.String
folder
The folder in which the resource is. |
System.String
resourceName
The name of the resource. |
Returns
System.Net.Http.HttpResponseMessage
The resource message. |
GetResource(String, String, String, String)
Gets a resource part of a document in multi-stream document format.
Declaration
public virtual HttpResponseMessage GetResource(string clientID, string instanceID, string documentID, string resourceID)
Parameters
System.String
clientID
The client session ID which contains the document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the document. |
System.String
resourceID
The ID of the requested resource. |
Returns
System.Net.Http.HttpResponseMessage
|
GetSearchResults(String, String, String, SearchArgs)
Retrieves the search metadata from resources and returns the search results that satisfy the passed arguments.
Declaration
public virtual HttpResponseMessage GetSearchResults(string clientID, string instanceID, string documentID, SearchArgs args)
Parameters
System.String
clientID
The client session ID which contains the document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the document. |
SearchArgs
args
The arguments used to perform the search. |
Returns
System.Net.Http.HttpResponseMessage
|
GetUserIdentity()
Override this method to substitute the default UserIdentity retrieval logic, which uses System.Web.HttpContext.Current.User.Identity.
Declaration
protected virtual UserIdentity GetUserIdentity()
Returns
UserIdentity
The UserIdentity object instance, that can be later retrieved by Current property or by using expression =UserIdentity. |
GetVersion()
Gets the version of Telerik Reporting
Declaration
public virtual HttpResponseMessage GetVersion()
Returns
System.Net.Http.HttpResponseMessage
Version number in string format |
KeepClientAlive(String)
Keeps the client alive, extending it by ClientSessionTimeout
Declaration
public virtual HttpResponseMessage KeepClientAlive(string clientID)
Parameters
System.String
clientID
The id of the client to be kept alive |
Returns
System.Net.Http.HttpResponseMessage
No content (204) or a bad request (400) if the client has expired |
OnCreateDocument(CreateDocumentEventArgs)
Called when document is requested, before rendering the document.
Declaration
protected virtual void OnCreateDocument(CreateDocumentEventArgs args)
Parameters
CreateDocumentEventArgs
args
The args describing the rendered document. |
OnGetDocument(GetDocumentEventArgs)
Called when document is requested, before sending the response.
Declaration
protected virtual void OnGetDocument(GetDocumentEventArgs args)
Parameters
GetDocumentEventArgs
args
The args describing the rendered document. |
ProcessDocumentId(String)
Declaration
protected virtual void ProcessDocumentId(string documentId)
Parameters
System.String
documentId
|
RegisterClient()
Registers new HTTP service client.
Declaration
public virtual HttpResponseMessage RegisterClient()
Returns
System.Net.Http.HttpResponseMessage
|
SendDocument(String, String, String, SendDocumentArgs)
Sends an e-mail message with attached document.
Declaration
public virtual HttpResponseMessage SendDocument(string clientID, string instanceID, string documentID, SendDocumentArgs args)
Parameters
System.String
clientID
The client session ID which contains the document. |
System.String
instanceID
The report instance used for the document. |
System.String
documentID
The ID of the document. |
SendDocumentArgs
args
The mail message args. |
Returns
System.Net.Http.HttpResponseMessage
|
SendMailMessage(MailMessage)
Sends an e-mail message containing a report document to its recipients. Override this method in order to effectively send the mail message.
Declaration
protected virtual HttpStatusCode SendMailMessage(MailMessage mailMessage)
Parameters
System.Net.Mail.MailMessage
mailMessage
The mail message to send |
Returns
System.Net.HttpStatusCode
The default value is NotImplemented. |
Remarks
The default implementation of this method is empty. Override this method in order to use the feature.
Examples
protected override HttpStatusCode SendMailMessage(MailMessage mailMessage)
{
using (var smtpClient = new SmtpClient("smtp.companyname.com", 25))
{
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);
}
return HttpStatusCode.OK;
}
Protected Overrides Function SendMailMessage(ByVal mailMessage As MailMessage) As HttpStatusCode
Using smtpClient = New SmtpClient("smtp.companyname.com", 25)
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
smtpClient.EnableSsl = True
smtpClient.Send(mailMessage)
End Using
Return HttpStatusCode.OK
End Function
UnregisterClient(String)
Removes existing client of the HTTP service by its ID.
Declaration
public virtual HttpResponseMessage UnregisterClient(string clientID)
Parameters
System.String
clientID
The ID of the client to be removed. |
Returns
System.Net.Http.HttpResponseMessage
|
Remarks
All cached data for the client will be cleared.