This is a migrated thread and some comments may be shown as answers.

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

1 Answer 412 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 17 Feb 2020, 08:42 PM

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.

1 Answer, 1 is accepted

Sort by
0
Carlos
Top achievements
Rank 1
answered on 18 Feb 2020, 03:07 PM

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;
            }

        }
    }

 

Tags
General Discussions
Asked by
Carlos
Top achievements
Rank 1
Answers by
Carlos
Top achievements
Rank 1
Share this question
or