private void GetReportData(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, ReportExecution2005.ParameterValue[] Parameters, string ParameterLanguage, string RenderFormat, out byte[] bytes) { bytes = null; string serviceUrl; string execUrl; BasicHttpBinding basicHttpBinding; ConfigureReportServerBinding(ReportServerPath, ReportMode, ReportHttpClientCredentialType, out serviceUrl, out execUrl, out basicHttpBinding); using (ReportingService2010.ReportingService2010SoapClient rsService = new ReportingService2010.ReportingService2010SoapClient(basicHttpBinding, new EndpointAddress(serviceUrl))) using (ReportExecution2005.ReportExecutionServiceSoapClient rsExec = new ReportExecution2005.ReportExecutionServiceSoapClient(basicHttpBinding, new EndpointAddress(execUrl))) { ReportingService2010.TrustedUserHeader trusteduserHeader; ReportExecution2005.TrustedUserHeader userHeader; GetHeaders(UserName, UserPassword, rsService, rsExec, out trusteduserHeader, out userHeader); ReportingService2010.SearchCondition condition = new ReportingService2010.SearchCondition(); condition.Condition = ReportingService2010.ConditionEnum.Equals; condition.ConditionSpecified = true; condition.Name = "Name"; ReportingService2010.SearchCondition[] conditions = new ReportingService2010.SearchCondition[1]; conditions[0] = condition; ReportingService2010.CatalogItem[] foundItems = null; condition.Values = new string[] { ReportName }; rsService.FindItems(trusteduserHeader , "/" + ReportFolder.TrimStart('/').TrimEnd('/') , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundItems); if (foundItems != null && foundItems.Count() > 0) { foreach (var item in foundItems) { if (item.Path == "/" + ReportFolder.TrimStart('/').TrimEnd('/') + "/" + ReportName) { ///Exporting to XML is not supported in SQL Server Express ///http://msdn.microsoft.com/en-us/library/cc645993.aspx string format = RenderFormat.ToUpper(); string historyID = null; string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; string encoding; string mimeType; string extension; string[] streamIDs = null; ReportExecution2005.Warning[] warnings = null; ReportExecution2005.ServerInfoHeader execServerHeader = new ReportExecution2005.ServerInfoHeader(); ReportExecution2005.ExecutionInfo execInfo = new ReportExecution2005.ExecutionInfo(); rsExec.LoadReport(userHeader, item.Path, historyID, out execServerHeader, out execInfo); ReportExecution2005.ExecutionHeader execHeader = new ReportExecution2005.ExecutionHeader(); execHeader.ExecutionID = execInfo.ExecutionID; rsExec.SetExecutionParameters(execHeader, userHeader, Parameters, ParameterLanguage, out execInfo); execServerHeader = rsExec.Render(execHeader, userHeader, format, devInfo, out bytes, out extension, out mimeType, out encoding, out warnings, out streamIDs); break; } } } } }
private static void GetHeaders(string UserName, string UserPassword, ReportingService2010.ReportingService2010SoapClient rsService, ReportExecution2005.ReportExecutionServiceSoapClient rsExec, out ReportingService2010.TrustedUserHeader trusteduserHeader, out ReportExecution2005.TrustedUserHeader userHeader) { rsService.ClientCredentials.SupportInteractive = false; rsService.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; rsService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; System.Net.NetworkCredential clientCredentials = new System.Net.NetworkCredential(UserName, UserPassword); if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(UserPassword) && UserName != "@UserName" && UserPassword != "@UserPassword") { rsService.ClientCredentials.Windows.ClientCredential = clientCredentials; rsService.ClientCredentials.UserName.UserName = UserName; rsService.ClientCredentials.UserName.UserName = UserPassword; } trusteduserHeader = new ReportingService2010.TrustedUserHeader(); trusteduserHeader.UserName = clientCredentials.UserName; userHeader = new ReportExecution2005.TrustedUserHeader(); userHeader.UserName = clientCredentials.UserName; if (rsExec != null) { rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; //rsExec.ClientCredentials.Windows.ClientCredential = credentials.GetCredential(new Uri(baseUrl), "NTLM"); } }