Problems authenticating to Report Service 2014 server via C# MVC5 application

Asked

Viewed 647 times

4

I’m having a problem connecting to the Report Service 2014 server via C# of an MVC4 project:

Setting:

  • A Server Report Service 2014 has been installed that will have numerous reports, due to the client having numerous SQL Server bases spread throughout the state of SP. the most viable solution was this because in Report Server we have to add several tals connections (Datasources).

up to here ok.

Problem:

  • There is a MVC5 application that will have a list of these reports, where the Client (user) will open tals to see. The issue is "I cannot connect to the Report Service Server", the error is:

    Remote server returned an error: (401) Não Autorizado.

    Ex: Code

    public FileContentResult teste()
    {
        NetworkCredential Credential = new NetworkCredential("/USER/", "/PASS/");
        WebClient client = new WebClient();
        client.Credentials = Credential;
    
        string reportURL = "http://localhost/report/Pages/ReportViewer.aspx?/Relatorios/ColaboradoresRpt&rs:Command=Render&rs:Format=pdf";
        return File(client.DownloadData(reportURL), "application/pdf");
    }
    

1 answer

1

Apparently the WebClient is not passing credentials to the Report Service.

If I were you, I’d try access using HttpClient with HttpClientHandler to specify the authentication data in greater detail.

In the example below, sending the authentication header meets the REST standard well. As I am not familiar with the Report Service authentication protocol, I would say that the default is similar, but some adjustment may be necessary:

using (var client = new HttpClient()) {
    var byteArray = Encoding.ASCII.GetBytes("Usuario:Senha");
    var header = new AuthenticationHeaderValue(
               "Basic", Convert.ToBase64String(byteArray));
    client.DefaultRequestHeaders.Authorization = header;

    var result = await client.GetByteArrayAsync(uri);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.