Dynamic Web Service Domain Configuration in Telerik Report Designer & Server

1 Answer 25 Views
AJAX and Web 2.0 Telerik Trainer
Prabesh
Top achievements
Rank 1
Prabesh asked on 06 Apr 2025, 01:32 PM | edited on 06 Apr 2025, 01:32 PM

 

Hi Telerik Team,

I am designing a report using Telerik Report Designer and have connected multiple Web Service Data Sources that require 2-step authentication.

The reports are stored on the Telerik Report Server and are displayed in my ASP.NET MVC project using report server credentials and the report path (Category/ReportName). I have created the following function to connect to the report server:

using System.Web;
using System.Web.Mvc;
using Telerik.Reporting;
using Telerik.ReportViewer.Mvc;
using System.Collections.Generic;
using System;

namespace Project.Extensions
{
    public static class ReportExtension
    {
        public static IReportViewerBuilder GetReportViewerConfig(this HtmlHelper htmlHelper, string reportId, string reportSource, Dictionary<string, string> reportParams)
        {
            var uriReportSource = new UriReportSource
            {
                Uri = reportSource
            };

            foreach (var param in reportParams)
            {
                uriReportSource.Parameters.Add(param.Key, param.Value);
            }

            return htmlHelper.TelerikReporting().ReportViewer()
                .Id(reportId)
                .ReportServer(new ReportServer()
                {
                    Url = ReadConfigData.REPORT_SERVER_URL,
                    Username = ReadConfigData.REPORT_SERVER_USERNAME,
                    Password = ReadConfigData.REPORT_SERVER_PASSWORD
                })
                .ReportSource(uriReportSource)
                .ViewMode(ViewMode.Interactive)
                .ScaleMode(ScaleMode.FitPageWidth)
                .PersistSession(false)
                .SendEmail(new SendEmail { Enabled = true })
                .Parameters(new Parameters
                {
                    Editors = new Editors
                    {
                        MultiSelect = EditorTypes.ComboBox,
                        SingleSelect = EditorTypes.ComboBox
                    }
                })
                .EnableAccessibility(false);
        }
    }
}


Scenario: My API domain is https://abcapi.com, which is used in every report under the "Configure Data Retrieval" window of the Web Service Data Source.

My Requirement: If the domain name changes, I have to manually update the domain in every report and each Web Service Data Source, which is time-consuming and inefficient.

Question: Is there a way to set the domain name dynamically, so that I only need to update it in one place? Also, where is the configuration of each Web Service Data Source stored — is it in the database or somewhere else?

Regards,
Prabesh Shrestha

Rhonda
Top achievements
Rank 1
commented on 08 Apr 2025, 04:10 AM | edited

Instead of hardcoding the domain in each report, use this configuration to dynamically retrieve the domain during runtime. For instance, you could use a web.config or appsettings.json file to define and update the domain in one place.

block blast


1 Answer, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 09 Apr 2025, 03:16 PM

Hi Prabesh,

The configuration of the WebServiceDataSource is stored in the definition of the report. For example, if you are using a TRDP/TRDX file, it is stored in its XML content:

<?xml version="1.0" encoding="utf-8"?>
<Report Width="17cm" Name="Report423421" xmlns="http://schemas.telerik.com/reporting/2023/3.0">
  <DataSources>
    <WebServiceDataSource ParameterValues="null" AuthParameterValues="null" ServiceUrl="https://jsonplaceholder.typicode.com/todos?id=1" Name="webServiceDataSource1" />
  </DataSources>

That being said, the easiest way to change the domain name for all WebServiceDataSource components dynamically is to use WebServiceDataSource parameters. For example, you could set a @url parameter in every single WebServiceDataSource component, and link it to a report parameter:

By changing the value of a single report parameter, you can ensure that this change is reflected wherever the parameter is used. I noticed that you already have logic in place for passing parameters dynamically through code. You could use a similar approach for the ServiceUrl parameter. However, please keep in mind that report parameters are evaluated only during the preview of the report, not at design time.

Could you please let me know if such solution meets your needs? I am looking forward to your reply!

Regards,
Petar
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Prabesh
Top achievements
Rank 1
commented on 18 Apr 2025, 09:34 AM

Hi Petar,

Please excuse the lateness; I was busy with another task.
I have tried the way you suggested. 
but I got an issue (the hostname could not be parsed).
Here are the screenshots of what I set up:

I have set her a report parameter as URL with my https://abc.com.




In the WebService Data Source in the Configure Data Retrieval, I have set Service URL as 
@url/api/clients and in the configure request parameters. I have set the two parameters, one for URL as 
@url :: Inline :: = Parameters.url.Value 

and another one for clients for the query string 
clients :: Query :: = Parameters. ClientId.Value :: EICc8mvazf62OpbNP1pw== (passed one encrypted client ID just for testing)










Using this set up I get the error : The hostname couldn't be parsed and I didn't get the model in the Data Explorer like below :




But when I provide the 
URL path in the design-time value as https://abc.com, then I will get the data. 
So, my question is, okay, I get the data if I set the value in design-time value, but I am going to send its value from my above code for client ID. 

string currentClientId = currentUser.ClientId.ToString();
string encClientId = Md5Encryption.Encrypt(currentClientId);
path = Md5Decryption.Decrypt(path); //decrypting path to get original path
var reportParams = new Dictionary<string, string> {
      {"userName", currentUser.FullName }
};

/*check client-specific report is opened by authorized client
 Set the report path to empty if opened by an unauthorized client.
*/
if (!string.IsNullOrEmpty(path))
{
    var report Url = new Uri(Request.Url, path);
    string clientId = HttpUtility. ParseQueryString(reportUrl.Query). Get("clientId");
    if (!string.IsNullOrEmpty(clientId) && clientId == encClientId)
{
        reportParams. Add("clientId", clientId);
}
    else if (!string.IsNullOrEmpty(clientId) && clientId != encClientId)
{
path = "";
}
}

var model = new TelerikReportViewModel
{
    Path = path.Split('?')[0] ,
    ReportParams = reportParams
};

Like this, now I want to send the URL like clientid so 
If I set the URL (https://prabesh.com), then will it change the value in design-time value? If not, then it won't be effective for my ASP.NET MVC project, as I have to set the design-time value in every data source. 


And 

Right Now, this is how I send the clientId here, and in the design-time value, I set it to empty, and it will be sent by my code as report params.

Is there any other way? 

I have also tried it like this by sending a dummy URL in the service URL as http://localhost/.






And in the configure request parameters, I have set this. 




and I get a different error in Data Explorer, as shown below:



Regards,
Prabesh Shrestha

Prabesh
Top achievements
Rank 1
commented on 22 Apr 2025, 09:15 AM | edited

Hi Petar,

I have tried sending the URL via the code, but in the configure request parameters, I have set the URL parameter part empty



While previewing the report in my ASP.NET MVC project, the URL is passed in every web data source, and it works like you suggested before. However, while designing, I have to pass the URL in the design-time value in every web data source, which is not effective, is it? because I have to set that in every part while designing, just to get the fields of the model. So, is there any way to not send the URL data in the design-time value for the design part, or is it mandatory?


Regards,
Prabesh Shrestha
Petar
Telerik team
commented on 22 Apr 2025, 12:02 PM

Hello Prabesh,

Thank you very much for the thorough explanation of your situation. The screenshots were very helpful.

Indeed, only runtime values can be dynamically set for parameters, as the report parameters are evaluated with the passed values during runtime. This is particularly useful if you have a dummy web service that can be used for design-time purposes to fill in the necessary fields in the expressions (and prevent any errors during design time). When the report is previewed, the runtime values will be utilized, ensuring that the correct data is displayed.

Design-time values are actually embedded within the report definition, and the only way to modify these values is directly through the web report designer. That being said, the ability to change these values by passing them during the initialization of the web report designer seems like a valuable feature to me. Therefore, I encourage you to submit this suggestion in our public feedback portal:

I recommend explaining your scenario as thoroughly as possible, and if it gathers enough interest within the community, we will certainly consider implementing it in one of our future releases.

I hope this helps. Please let me know if you have any further questions.

Regards,
Petar

Prabesh
Top achievements
Rank 1
commented on 24 Apr 2025, 07:57 AM

Hello Petar,

Thank you very much for the detailed response and clarification regarding runtime values being the only way to dynamically set parameters. Your explanation really helped clear up my doubts.

As you mentioned, the ability to change these values by passing them during the initialization of the Web Report Designer definitely seems like a valuable feature. I believe it would greatly benefit many Telerik users, especially those working with dynamic data sources and real-time report configurations.

As you recommended, I will submit this suggestion in the Feedback Portal.

Once again, thank you so much for your guidance and continuous support throughout this process.

Best Regards,
Prabesh Shrestha

Tags
AJAX and Web 2.0 Telerik Trainer
Asked by
Prabesh
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or