How do you change the ServiceUrl in a Report in a WebServiceDataSource

2 posts, 0 answers
  1. Carlos
    Carlos avatar
    17 posts
    Member since:
    Jun 2019

    Posted 17 Feb Link to this post

    I have been researching all day I can't find a solution.  I have tried to build a custom resolver to change the server name and port as a test.  I have coded this class it returns null because I cannot determine how to return a ReportSource.

    public class TexasProtaxCustomReportResolver : Telerik.Reporting.Services.Engine.IReportResolver
        {
            public Telerik.Reporting.ReportSource Resolve(string reportName)
            {
                var reportPacker = new ReportPackager();
                using (var sourceStream = System.IO.File.OpenRead(reportName))
                {
                    var report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
                    var webServiceDataSource = (WebServiceDataSource)report.DataSource;
                    string url = webServiceDataSource.ServiceUrl;
                    url = url.ToLower().Replace("localhost:5001", "localhost:44384");
                    webServiceDataSource.ServiceUrl = url;
                   
                    return null;
                }

            }
        }

    In the ReportsConttroller I have tried adding the resolver but it has an error:

            public ReportsController(ConfigurationService configSvc)
            {
                this.reportsPath = Path.Combine(configSvc.Environment.WebRootPath, "Reports");

                this.ReportServiceConfiguration = new ReportServiceConfiguration
                {
                    ReportingEngineConfiguration = configSvc.Configuration,
                    HostAppId = "ReportsService",
                    Storage = new FileStorage(),
                    ReportResolver = new ReportTypeResolver()
                            .AddFallbackResolver(new ReportFileResolver(this.reportsPath))
                                .AddFallbackResolver(new TexasProtaxCustomReportResolver())
                };
            }

     

    Any assistance would be appreciated.

  2. Carlos
    Carlos avatar
    17 posts
    Member since:
    Jun 2019

    Posted 18 Feb Link to this post

    I solved the problem.  It had multiple issues.  First in the Report Controller it should be:

            public ReportsController(ConfigurationService configSvc)
            {
                this.reportsPath = Path.Combine(configSvc.Environment.WebRootPath, "Reports");
                this.ReportServiceConfiguration = new ReportServiceConfiguration
                {
                    ReportingEngineConfiguration = configSvc.Configuration,
                    HostAppId = "ReportsService",
                    Storage = new FileStorage(),
                    ReportResolver = new ReportTypeResolver()
                                .AddFallbackResolver(new TexasProtaxCustomReportResolver(this.reportsPath))
                };
            }

    Second in the Resolver:

        public class TexasProtaxCustomReportResolver : Telerik.Reporting.Services.Engine.IReportResolver
        {
            private readonly string _path;
            public TexasProtaxCustomReportResolver(string path)
            {
                _path = path;
                
            }

            public Telerik.Reporting.ReportSource Resolve(string reportName)
            {
                var reportPacker = new ReportPackager();

                string reportPath = Path.Combine(_path, reportName);
                using (var sourceStream = System.IO.File.OpenRead( reportPath))
                {
                    var report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
                    var webServiceDataSource = (WebServiceDataSource)report.DataSource;
                    string url = webServiceDataSource.ServiceUrl;
                    url = url.ToLower().Replace("localhost:5001", "localhost:44384");
                    webServiceDataSource.ServiceUrl = url;
                    var irs = new InstanceReportSource
                    {
                        ReportDocument = report
                    };

                    return irs;
                }

            }
        }

     

Back to Top