Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

I'm not able to get new data from the same SSRS report on Reporting Services when calling from a Blazor application. What should I do different?

$
0
0

Here is the class I call from my Report Viewer Component:

public class SsrsReportService{private readonly IHttpClientFactory _httpClientFactory;

public SsrsReportService(IHttpClientFactory httpClientFactory){    _httpClientFactory = httpClientFactory;}/// <summary>/// Get the report PDF bytes from SSRS./// </summary>/// <param name="reportPath">The report name.</param>/// <returns></returns>/// <exception cref="Exception"></exception>public async Task<byte[]> GetReportPdfAsync(string reportPath){    var _http = _httpClientFactory.CreateClient("SsrsReportServiceClient");    try    {        var rptSvrAddr = mmAppBase.AppSettingsMgr.GetSetting("ReportServer");        var serverReportPath = $"{rptSvrAddr}{reportPath}&rs:Format=PDF";        var request = new HttpRequestMessage(HttpMethod.Get, serverReportPath);        request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/pdf"));        request.Headers.IfModifiedSince = new DateTimeOffset(DateTime.Now);         var response = await _http.SendAsync(request);        if (!response.IsSuccessStatusCode)            throw new Exception($"Failed to get report: {response.StatusCode}");        return await response.Content.ReadAsByteArrayAsync();                    }    catch (Exception)    {        throw;    }    finally    {       _http.Dispose(); // Ensure the HttpClient is disposed    }}

}

Here is how I add it my service layer:

// Add Reporting Services Base Address.services.AddHttpClient("SsrsReportServiceClient")    .ConfigureHttpClient(client =>    {        var baseRptSvr = mmAppBase.AppSettingsMgr.GetSetting("BaseRptSrv");        client.BaseAddress = new Uri(baseRptSvr);    }).ConfigurePrimaryHttpMessageHandler(() =>    {        // Use default credentials for SSRS        return new HttpClientHandler        {            UseDefaultCredentials = true,            AllowAutoRedirect = false // Prevent automatic redirects        };    });services.AddTransient<SsrsReportService>();

Each time I call the GetReportPdfAsync() method, I believe I'm creating a new http client and a new request. However I keep getting the same data for the report. When I close the application in Visual Studio and start it up again, then it gets the right data on the first call. After that, it continues to get the same data no matter the parameters. Any suggestions on how I should be doing this instead would be appreciated? Thanks!


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>