Search results

Integrate the component with Report Server

You can integrate Report Designer with Report Server to create, edit, browse and publish reports using the Report Server built-in API service.

  • The Report Designer requires the serviceAuthorizationToken to perform the API actions with Syncfusion Report Server. Create a token for the user by using the server RESTful API, you can use the following code in HomeController.cs to generate the token.
    public partial class HomeController : Controller
    {
        public IActionResult Index()
        {
            ViewBag.ServiceAuthorizationToken = this.GenerateToken("http://reportserver.syncfusion.com/", "guest", "demo");
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        public string GenerateToken(string serverUrl, string userName, string password)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(serverUrl);
                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("/api/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; }
    }
  • Set the Syncfusion Report Server built-in service URL to the serviceUrl property and assign the created token to serviceAuthorizationToken property. You can use the following code in your CSHTML page.
    <sf-report-designer id="designer" service-url="http://reportserver.syncfusion.com/ReportService/api/Designer" service-authorization-token="@ViewBag.ServiceAuthorizationToken" ></sf-report-designer>