ActiveReports 12 Server User Guide
Rendering a Code-Based Section Report
ActiveReports 12 Server User Guide > Samples and Walkthroughs > Walkthroughs > Rendering a Code-Based Section Report

You can render reports hosted on ActiveReports Server to PDF or Excel format using the RenderReport method. This topic explains how to render an XML-based section report to PDF format.

Note: You can also render a code-based section report or a page report to PDF format using the same steps.
  1. From the Visual Studio File menu, select New Project.
  2. In the New Project dialog that appears, select Visual C# or Visual Basic from the template list, click Windows and select Console Application.
  3. Rename the project to RenderReport and сlick OK.
    Note: The target framework of the project must be set to .NET Framework 4.5 or above.
  4. From the Visual Studio Project menu, select Add Service Reference.
  5. In the Add Service Reference dialog that appears, enter the following address in the Address field.
    Paste in the Address box, replacing 8080 with the site port where you installed ActiveReports 12 Server.
    Copy Code
    http://localhost:8080/ReportService.svc
  6. Click Go, and when the ReportService appears in the Services pane, you can expand it and select the service interface to reveal its available operations in the pane to the right.
  7. Rename the Namespace that you want to use to ReportService and click OK. The reference appears in the Solution Explorer.
  8. Open the app.config file and in the address attribute of the endpoint element, check whether the service address set in step 5 is correct. Replace the address if it is not correct. 
    Confirm the value of the address attribute in the endpoint element of the app.config file
    Copy Code
    <client>
    <endpoint address="http://localhost:8080/ReportService.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IReportService"
    contract="ReportService.IReportService" name="WSHttpBinding_IReportService" />
    </client>
    Note: The service address may not get updated automatically by the server configuration of the installed ActiveReports Server.
  9. In Program.cs or Module1.vb, add the following statements to the using/Imports statements at the top of the code.

    Visual Basic

    Visual Basic code (Add to the list of Imports statements at the top of the code.)
    Copy Code
    Imports System.IO
    Imports System.Net                                                      
    Imports RenderReport.ReportService                            
    

    C#

    C# code(Add to the list of using statements at the top of the code.)
    Copy Code
    using System.IO;
    using System.Net;
    using RenderReport.ReportService;                                       
    
  10. In Program.cs or Module1.vb, add the following code into the Main method.

    Visual Basic

    Visual Basic code (Paste the following code into the Main method of the Module1 module declaration)
    Copy Code
    Dim serverUserName = "USER"
    Dim serverUserPwd = "PASS"
    Dim reportService = New ReportServiceClient("WSHttpBinding_IReportService")
    Dim securityToken = reportService.Login(serverUserName, serverUserPwd, Nothing, True)
    ' Get the report list from internal storage.
    Dim description = reportService.[Select](securityToken, New Query())
    ' Get the report description of output target.
    Dim TargetRepDescription As New ReportDescription()
    For Each des As ReportDescription In description
    If des.Name = "Payment Slip" Then
    TargetRepDescription = des
    Exit For
    End If
    Next
    ' Output into PDF
    Dim result = reportService.RenderReport(securityToken, TargetRepDescription, New RenderOptions() With {.Extension = "PDF"})
    Dim info As RequestInfo
    Do
    info = reportService.GetRequestStatus(securityToken, Result.Info.RequestId).Info
    Loop While info.State = RequestState.Pending OrElse info.State = RequestState.Running
    If info.State = RequestState.Accomplished Then
    Using client = New WebClient()
    client.DownloadFile(http://localhost:8080/cache/ + info.PrimaryUrl, "C:\work\test.pdf")
    End Using
    End If

    C#

    C# code (Paste the following code into the Main method of the Program class declaration)
    Copy Code
    var serverUserName = "USER";
    var serverUserPwd = "PASS";
    var reportService = new ReportServiceClient("WSHttpBinding_IReportService");
    var securityToken = reportService.Login(serverUserName, serverUserPwd, null, true);
    // Get the report list from internal storage.
    var description = reportService.Select(securityToken, new Query());
    // Get the report description of output target.
    ReportDescription TargetRepDescription = new ReportDescription();
    foreach (var des in description)
    {
    if (des.Name == "Payment Slip")
    {
    TargetRepDescription = des;
    break;
    }
    }
    // Output into PDF
    var result = reportService.RenderReport(securityToken, TargetRepDescription, new RenderOptions { Extension = "PDF" });
    RequestInfo info;
    do
    {
    info = reportService.GetRequestStatus(securityToken, result.Info.RequestId).Info;
    } while (info.State == RequestState.Pending || info.State == RequestState.Running);
    if (info.State == RequestState.Accomplished)
    {
    using (var client = new WebClient())
    {
    client.DownloadFile("http://localhost:8080/cache/" + info.PrimaryUrl, @"C:\work\test.pdf");
    }
    }
  11. Run the project.
See Also