Load Bold Reports® Report Server reports
To load Bold Reports® Report Server reports in the UWP Report Viewer, set the service URL, server URL, and report path of your Report Server, without creating a Web API service. Bold Reports® Report Server provides the built-in Web API service that helps you display the server reports.
- Set the Bold Reports® Report Server built-in service URL
ReportServiceURLandReportServerUrl,ReportServerCredential,ReportPathto a report deployed on the server. You can use the following complete code in your application to render the Bold Reports® Report Server reports.
If you need to know the difference between
reportServiceUrlandreportServerUrl, refer to the Difference between Report Service URL and Report Server URL.
this.ReportViewer.ReportServiceURL = @"https://on-premise-demo.boldreports.com/reporting/reportservice/api/Viewer/";
this.ReportViewer.ReportServerUrl = @"https://on-premise-demo.boldreports.com/reporting/api/site/site1";
this.ReportViewer.ServiceAuthorizationToken = GenerateToken("[email protected]", "demo");
this.ReportViewer.ReportServiceRequestBegin += (sen, arg) =>
{
arg.HttpClient.DefaultRequestHeaders.Add("serverurl", "https://on-premise-demo.boldreports.com/reporting/api/site/site1");
};
this.ReportViewer.ReportPath = @"/Sample Reports/Company Sales";
this.ReportViewer.RefreshReport();
public string GenerateToken(string userName, string password)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", userName),
new KeyValuePair<string, string>("password", password)
});
var result = client.PostAsync("https://on-premise-demo.boldreports.com/reporting/api/site/site1/token", content).Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
var token = JsonConvert.DeserializeObject<Token>(resultContent);
return token.token_type + " " + token.access_token;
}
}
public class Token
{
public string access_token { get; set; }
public string token_type { get; set; }
public string expires_in { get; set; }
public string userName { get; set; }
public string serverUrl { get; set; }
public string password { get; set; }
}