
SQL Server Reporting Services (SSRS) remains a popular solution for generating operational and financial reports in organizations that rely on Microsoft SQL Server. Many modern applications, however, are built as web or mobile front ends that communicate with back-end APIs. A common requirement is to let users request a report through the application and download it as a PDF or Excel file. The cleanest way to achieve this is to call the SSRS report from a Web API, which handles authentication, parameters, and rendering on the server side. This guide explains how to do it step by step.
Modernize Your Reporting With AAMAX.CO
Integrating legacy reporting tools with modern applications requires a solid understanding of both worlds. AAMAX.CO is a full-service digital marketing company offering web development, digital marketing, and SEO services worldwide. Their developers build secure APIs, dashboards, and reporting integrations through their web application development services. They help businesses deliver reports seamlessly inside customer portals and internal tools.
Understanding the Options
There are three main ways to render SSRS reports programmatically:
- URL Access: Construct a URL to the report server with parameters and a format command, then download the result.
- SOAP Web Service (ReportExecution2005): A more structured API for loading reports, setting parameters, and rendering output.
- SSRS REST API: Available in SQL Server 2017 and later, mainly for catalog management rather than rendering.
For most Web API scenarios, URL Access is the simplest and most widely used approach.
Step 1: Confirm the Report Server URL and Report Path
Identify your report server URL, typically something like http://reportserver/ReportServer, and the report path, such as /Sales/MonthlySummary. Test the report in a browser first to confirm it renders correctly with the parameters you plan to pass.
Step 2: Build the Rendering URL
SSRS URL Access uses special commands prefixed with rs: and report parameters passed by name:
http://reportserver/ReportServer?/Sales/MonthlySummary&rs:Format=PDF&Month=10&Year=2026Supported formats include PDF, EXCELOPENXML, WORDOPENXML, CSV, XML, and IMAGE. Always URL-encode parameter values to avoid errors with special characters.
Step 3: Configure Authentication
SSRS typically uses Windows authentication. Your Web API must present valid credentials to the report server. Options include running the API under a service account with report permissions and using default credentials, or supplying a specific NetworkCredential. Store usernames and passwords in secure configuration, such as environment variables or a secret manager, never in source code.
Step 4: Create the Web API Endpoint
Here is an example ASP.NET Core controller that calls SSRS and returns a PDF:
[ApiController]
[Route("api/reports")]
public class ReportsController : ControllerBase
{
private readonly IConfiguration _config;
public ReportsController(IConfiguration config)
{
_config = config;
}
[HttpGet("monthly-summary")]
public async Task<IActionResult> GetMonthlySummary(int month, int year)
{
var baseUrl = _config["Ssrs:ServerUrl"];
var url = baseUrl + "?/Sales/MonthlySummary&rs:Format=PDF"
+ "&Month=" + month + "&Year=" + year;
var handler = new HttpClientHandler
{
Credentials = new NetworkCredential(
_config["Ssrs:User"],
_config["Ssrs:Password"],
_config["Ssrs:Domain"])
};
using var client = new HttpClient(handler);
var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
return StatusCode((int)response.StatusCode, "Report rendering failed.");
}
var bytes = await response.Content.ReadAsByteArrayAsync();
return File(bytes, "application/pdf", "MonthlySummary.pdf");
}
}In production, register HttpClient through IHttpClientFactory to manage connections efficiently.
Step 5: Validate User Input and Permissions
Never pass user input directly to the report server without validation. Check that parameters are within acceptable ranges and that the requesting user is authorized to view the requested data. Your Web API acts as a security gateway, ensuring users only access reports and records they are permitted to see.
Step 6: Call the Endpoint From Your Front End
Your web application can now request the report from the API. In JavaScript, fetch the endpoint, convert the response to a Blob, and trigger a download or display the PDF in a new tab. Mobile applications can similarly download and open the file using native viewers.
Step 7: Optimize Performance
Large reports can take time to render. Consider these optimizations:
- Use report caching or snapshots in SSRS for frequently requested reports.
- Generate heavy reports asynchronously and notify users when they are ready.
- Set appropriate HttpClient timeouts for long-running reports.
- Optimize the underlying SQL queries and datasets.
Using the SOAP Execution Service
If you need more control, such as retrieving available parameters dynamically or handling complex multi-value parameters, use the ReportExecution2005 SOAP endpoint. Add a service reference in your .NET project, call LoadReport, SetExecutionParameters, and Render, then return the resulting byte array. This approach is more verbose but offers greater flexibility.
Troubleshooting Common Issues
- 401 Unauthorized: Verify credentials and that the account has Browser role permissions on the report.
- Parameter errors: Check parameter names, which are case-sensitive, and data types.
- Timeouts: Increase timeouts or optimize the report query.
Conclusion
Calling an SSRS report from a Web API lets you bring trusted reporting into modern applications. Build a rendering URL or use the SOAP execution service, authenticate securely, validate inputs, and return the file to users. With caching and proper error handling, your reports will be fast, secure, and easy to access from any device.
