Based on the problem in this question , I find myself in the same situation, I have a report builder web service , it is on the server and I cannot access it from a client.
To allow me access I have followed these instructions but in vain, my connection code is this:
Connection strings:
private int _commandTimeout = 600;
private Uri _reportServerUrl = new Uri("http://<Servidor>:80/ReportServer");
private string _connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
private ReportViewer _reportViewer = new ReportViewer();
access function:
public string CargaInforme(int reportId)
{
string nomInforme = "";
using (SqlConnection sqlConn = new SqlConnection(_connectionString))
{
DataSet reportAccessInfo = SP_RPT_GET_REPORT_INFO(sqlConn, reportId);
if (reportAccessInfo != null && reportAccessInfo.Tables.Count > 0 && reportAccessInfo.Tables[0].Rows.Count > 0)
{
Uri _reportServerUrl = new Uri(GetReportServer());
this._reportViewer.ProcessingMode = ProcessingMode.Remote;
this._reportViewer.SizeToReportContent = true;
this._reportViewer.ZoomMode = ZoomMode.FullPage;
DataRow row = reportAccessInfo.Tables[0].Rows[0];
ServerReport serverReport = this._reportViewer.ServerReport;
serverReport.ReportServerUrl = _reportServerUrl;
serverReport.ReportPath = (row["reportPath"].ToString().StartsWith("/") ? "" : "/") + row["reportPath"].ToString();
string uriString = row["reportServerPath"].ToString().Trim();
Uri uri = (Uri)null;
int num = 0;
ref Uri local = ref uri;
if (Uri.TryCreate(uriString, (UriKind)num, out local))
{
serverReport.ReportServerUrl = uri;
}
//Aqui me produce el 401
ReportParameterInfoCollection parameters = this._reportViewer.ServerReport.GetParameters();
if (parameters.Count == 0)
this._reportViewer.ServerReport.Refresh();
ViewBag.ReportViewer = this._reportViewer;
nomInforme = row["reportDesc"].ToString();
}
}
return nomInforme;
}
Why does this error appear on certain clients and how can I solve it?
EDIT 1
The server and client are in the same domain. This question has not been able to provide me with the solution either since it is old
Adding the class
ReportServerCredentials
and defining it as follows:And calling this in the function:
According to Mozilla it
401
means:So you have to send the credentials to the server using
WWW-Authenticate
so that it allows you to consume the service or disable the authentication that you have configured in the IIS and change it to anonymous.