예제 #1
1
        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;
                        }
                    }
                }
            }
        }
예제 #2
0
        private ReportExecution2005.ReportExecutionServiceSoapClient CreateReportExecution2005Client()
        {
            if (!Enum.TryParse <HttpClientCredentialType>(
                    _reportingServicesConfiguration.CredentialType,
                    out var httpClientCredentialType))
            {
                throw new Exception($"Invalid value for CredentialType: {_reportingServicesConfiguration.CredentialType}. Check the settings file.");
            }

            var rsBinding = new BasicHttpBinding
            {
                Security =
                {
                    Mode      = _reportingServicesConfiguration.Execution2005Url.StartsWith("https", StringComparison.InvariantCultureIgnoreCase) ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.TransportCredentialOnly,
                    Transport = { ClientCredentialType = httpClientCredentialType }
                },
                MaxReceivedMessageSize = 10485760 // 10MB size limit on response to allow for larger files
            };

            EndpointAddress rsEndpointAddress = new EndpointAddress(_reportingServicesConfiguration.Execution2005Url);

            // Create the execution service SOAP Client
            var rsClient = new ReportExecution2005.ReportExecutionServiceSoapClient(rsBinding, rsEndpointAddress);

            rsClient.Endpoint.EndpointBehaviors.Add(new LogBehavior());

            // Setup access credentials
            var clientCredentials = new NetworkCredential(_reportingServicesConfiguration.UserName, _reportingServicesConfiguration.Password, _reportingServicesConfiguration.Domain);

            rsClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            rsClient.ClientCredentials.Windows.ClientCredential          = clientCredentials;

            rsClient.ClientCredentials.UserName.UserName = !string.IsNullOrWhiteSpace(_reportingServicesConfiguration.Domain) ? $"{_reportingServicesConfiguration.Domain}\\{_reportingServicesConfiguration.UserName}" : _reportingServicesConfiguration.UserName;
            rsClient.ClientCredentials.UserName.Password = _reportingServicesConfiguration.Password;

            return(rsClient);
        }
예제 #3
0
 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");
     }
 }
예제 #4
0
        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;
                            }
                        }
                    }
                }
        }