public static ReportService.ReportParameter[] GetReportParameters(ReportViewerModel model, bool forRendering = false) { var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportService2005.asmx"; var basicHttpBinding = _initializeHttpBinding(url, model); var service = new ReportService.ReportingService2005SoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url)); service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; service.ClientCredentials.Windows.ClientCredential = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials); var cred = model.Credentials?.GetCredential(new Uri(url), "Basic"); service.ClientCredentials.UserName.UserName = cred?.UserName; service.ClientCredentials.UserName.Password = cred?.Password; string historyID = null; ReportService.ParameterValue[] values = null; ReportService.DataSourceCredentials[] rsCredentials = null; var parameters = service.GetReportParametersAsync(model.ReportPath, historyID, false, values, rsCredentials).Result; //set it to load the not for rendering so that it's hopefully quicker than the whole regular call if (model != null && model.Parameters != null && model.Parameters.Any()) { var tempParameters = new List <ReportService.ParameterValue>(); foreach (var parameter in parameters) { if (model.Parameters.ContainsKey(parameter.Name)) { var providedParameter = model.Parameters[parameter.Name]; if (providedParameter != null) { foreach (var value in providedParameter.Where(x => !String.IsNullOrEmpty(x))) { tempParameters.Add(new ReportService.ParameterValue() { Label = parameter.Name, Name = parameter.Name, Value = value }); } } } } values = tempParameters.ToArray(); } parameters = service.GetReportParametersAsync(model.ReportPath, historyID, forRendering, values, rsCredentials).Result; return(parameters); }
public static ReportService.CatalogItem[] GetCatalogTreeView(ReportViewerModel model, string CatalogPath = "/", bool Recursive = false) { var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportService2005.asmx"; var basicHttpBinding = _initializeHttpBinding(url, model); var service = new ReportService.ReportingService2005SoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url)); service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; service.ClientCredentials.Windows.ClientCredential = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultNetworkCredentials); ReportService.CatalogItem[] values; values = service.ListChildrenAsync(CatalogPath, Recursive).Result; return(values); }
public static ReportService.ReportParameter[] GetReportParameters(ReportViewerModel model, bool forRendering = false) { var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportService2005.asmx"; var basicHttpBinding = _initializeHttpBinding(); var service = new ReportService.ReportingService2005SoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url)); service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; service.ClientCredentials.Windows.ClientCredential = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials); string historyID = null; ReportService.ParameterValue[] values = null; ReportService.DataSourceCredentials[] rsCredentials = null; var parameters = service.GetReportParametersAsync(model.ReportPath, historyID, forRendering, values, rsCredentials).Result; return(parameters); }
public string RenderReport(string reportpath, SSRSExportType ExportType) { using (ReportExecutionService.ReportExecutionServiceSoapClient res = new ReportExecutionService.ReportExecutionServiceSoapClient("ReportExecutionServiceSoap")) { ReportExecutionService.ExecutionHeader ExecutionHeader = new ReportExecutionService.ExecutionHeader(); ReportExecutionService.TrustedUserHeader TrusteduserHeader = new ReportExecutionService.TrustedUserHeader(); res.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; ReportServerCreds rsc = GetReportCreds(); res.ClientCredentials.Windows.ClientCredential.Domain = rsc.Domain; res.ClientCredentials.Windows.ClientCredential.UserName = rsc.UserName; res.ClientCredentials.Windows.ClientCredential.Password = rsc.Password; res.Open(); ReportExecutionService.ExecutionInfo ei = new ReportExecutionService.ExecutionInfo(); string format = null; string deviceinfo = null; string mimetype = null; if (ExportType.ToString().ToLower() == "html") { format = "HTML4.0"; deviceinfo = @"<DeviceInfo><StreamRoot>/</StreamRoot><HTMLFragment>True</HTMLFragment></DeviceInfo>"; } else if (ExportType.ToString().ToLower() == "pdf") { format = "PDF"; mimetype = ""; } byte[] results = null; string extension = null; string Encoding = null; ReportExecutionService.Warning[] warnings; string[] streamids = null; string historyid = null; ReportExecutionService.ExecutionHeader Eheader; ReportExecutionService.ServerInfoHeader serverinfoheader; ReportExecutionService.ExecutionInfo executioninfo; // Get available parameters from specified report. ParameterValue[] paramvalues = null; DataSourceCredentials[] dscreds = null; ReportParameter[] rparams = null; using (ReportService.ReportingService2005SoapClient lrs = new ReportService.ReportingService2005SoapClient("ReportingService2005Soap")) { lrs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; lrs.ClientCredentials.Windows.ClientCredential.Domain = rsc.Domain; lrs.ClientCredentials.Windows.ClientCredential.UserName = rsc.UserName; lrs.ClientCredentials.Windows.ClientCredential.Password = rsc.Password; lrs.GetReportParameters(reportpath, historyid, false, paramvalues, dscreds, out rparams); } // Set report parameters here //List<ReportExecutionService.ParameterValue> parametervalues = new List<ReportExecutionService.ParameterValue>(); //string enumber = Session["ENumber"] as string; //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "ENumber", Value = enumber }); //if (date != null) //{ // DateTime dt = DateTime.Today; //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "AttendanceDate", Value = dt.ToString("MM/dd/yyyy")}); //} //if (ContainsParameter(rparams, "DEEWRID")) //{ //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "DEEWRID", Value = deewrid }); //} //if (ContainsParameter(rparams, "BaseHostURL")) //{ // parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "BaseHostURL", Value = string.Concat("http://", Request.Url.Authority) }); //} //parametervalues.Add(new ReportExecutionService.ParameterValue() {Name="AttendanceDate",Value=null }); //parametervalues.Add(new ReportExecutionService.ParameterValue() { Name = "ENumber", Value = "E1013" }); try { Eheader = res.LoadReport(TrusteduserHeader, reportpath, historyid, out serverinfoheader, out executioninfo); serverinfoheader = res.SetExecutionParameters(Eheader, TrusteduserHeader, parametervalues.ToArray(), null, out executioninfo); res.Render(Eheader, TrusteduserHeader, format, deviceinfo, out results, out extension, out mimetype, out Encoding, out warnings, out streamids); string exportfilename = string.Concat(enumber, reportpath); if (ExportType.ToString().ToLower() == "html") { //write html string html = string.Empty; html = System.Text.Encoding.Default.GetString(results); html = GetReportImages(res, Eheader, TrusteduserHeader, format, streamids, html); return(html); } else if (ExportType.ToString().ToLower() == "pdf") { //write to pdf Response.Buffer = true; Response.Clear(); Response.ContentType = mimetype; //Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.pdf", exportfilename)); Response.BinaryWrite(results); Response.Flush(); Response.End(); } } catch (Exception e) { Response.Write(e.Message); } } }