Exemplo n.º 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;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
1
        private void CreateLinkedReport(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode
            , HttpClientCredentialType ReportHttpClientCredentialType
            , string ReportFolder, string ReportName
            , string LinkedReportPath
            , ReportingService2010.Property[] LinkedReportProperties
            , XElement xLinkedReportParameters
            //, string ParameterLanguage
            )
        {
            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)))
            {
                ReportingService2010.TrustedUserHeader trusteduserHeader;
                ReportExecution2005.TrustedUserHeader userHeader;
                GetHeaders(UserName, UserPassword, rsService, null, 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.TrimStart('/').TrimEnd('/') };
                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)
                        {
                            string parentReportPath = item.Path;
                            try
                            {
                                string linkedReportName = LinkedReportPath.Substring(LinkedReportPath.LastIndexOf('/') + 1).TrimStart('/').TrimEnd('/');
                                string linkedReportFolderPath = LinkedReportPath.Substring(0, LinkedReportPath.LastIndexOf('/')).TrimEnd('/');
                                CheckLinkedFolderExists(rsService, trusteduserHeader, condition, conditions, linkedReportFolderPath);
                                ReportingService2010.CatalogItem[] foundLinkedItems = null;
                                condition.Values = new string[] { linkedReportName };
                                rsService.FindItems(trusteduserHeader
                                    , linkedReportFolderPath
                                    , ReportingService2010.BooleanOperatorEnum.And
                                    , new ReportingService2010.Property[0]
                                    , conditions
                                    , out foundLinkedItems);

                                if (foundLinkedItems == null || (foundLinkedItems != null && foundLinkedItems.Count() == 0))
                                {
                                    rsService.CreateLinkedItem(trusteduserHeader
                                        , linkedReportName
                                        , linkedReportFolderPath
                                        , parentReportPath
                                        , LinkedReportProperties);
                                }
                                if (xLinkedReportParameters != null)
                                {
                                    //// List of properties to copy from parent to linked reports. ???
                                    //var requestedProperties = new ReportingService2010.Property[] {
                                    //    new ReportingService2010.Property { Name = "PageHeight" },
                                    //    new ReportingService2010.Property { Name = "PageWidth" },
                                    //    new ReportingService2010.Property { Name = "TopMargin" },
                                    //    new ReportingService2010.Property { Name = "BottomMargin" },
                                    //    new ReportingService2010.Property { Name = "LeftMargin" },
                                    //    new ReportingService2010.Property { Name = "RightMargin" }
                                    //};

                                    IEnumerable<XElement> linkedReportParams = xLinkedReportParameters.Descendants("Param");
                                    if (linkedReportParams.Count() > 0)
                                    {
                                        List<ReportingService2010.ItemParameter> ItemParamsList = new List<ReportingService2010.ItemParameter>();
                                        foreach (var linkedReportParam in linkedReportParams)
                                        {
                                            string defaultValues = linkedReportParam.Attribute("DefaultValues").Value;
                                            if (!string.IsNullOrEmpty(defaultValues))
                                            {
                                                ReportingService2010.ItemParameter[] parentReportParams = null;
                                                rsService.GetItemParameters(trusteduserHeader
                                                    , parentReportPath
                                                    , null
                                                    , false, null, null, out parentReportParams);

                                                bool paramExists = false;
                                                ReportingService2010.ItemParameter ip = new ReportingService2010.ItemParameter();
                                                ip.Name = linkedReportParam.Attribute("Name").Value;
                                                foreach (var parentReportParam in parentReportParams)
                                                {
                                                    if (parentReportParam.Name == ip.Name)
                                                    {
                                                        ip.AllowBlank = parentReportParam.AllowBlank;
                                                        ip.MultiValue = parentReportParam.MultiValue;
                                                        ip.Nullable = parentReportParam.Nullable;
                                                        ip.Prompt = parentReportParam.Prompt;
                                                        ip.PromptUser = parentReportParam.PromptUser;
                                                        ip.PromptUserSpecified = parentReportParam.PromptUserSpecified;
                                                        paramExists = true;
                                                        break;
                                                    }

                                                }
                                                if (paramExists)
                                                {
                                                    ip.DefaultValues = defaultValues.Split(',');
                                                    if (linkedReportParam.Attribute("Hide") != null
                                                        && linkedReportParam.Attribute("Hide").Value.ToLower() == "true")
                                                    { //hide the paramerter using combination of parameters. There is no Hide property which reflects UI Hide checkbox
                                                        ip.PromptUser = false;
                                                        ip.PromptUserSpecified = false;
                                                        ip.Prompt = null;
                                                    }
                                                    ItemParamsList.Add(ip);
                                                }
                                            }
                                        }
                                        rsService.SetItemParameters(trusteduserHeader, LinkedReportPath, ItemParamsList.ToArray());
                                    }
                                }
                            }
                            catch (SoapException ex)
                            {
                                LogMessage("Not able to create linked report " + LinkedReportPath + " Error: " + ex.Message);
                                throw;
                            }

                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 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");
     }
 }
Exemplo n.º 4
0
        private void CheckLinkedFolderExists(ReportingService2010.ReportingService2010SoapClient rsService
                                             , ReportingService2010.TrustedUserHeader trusteduserHeader
                                             , ReportingService2010.SearchCondition condition
                                             , ReportingService2010.SearchCondition[] conditions
                                             , string linkedReportFolderPath
                                             )
        {
            string parentFolderPath = @"/";

            string[] folders = linkedReportFolderPath.Split('/');
            for (int i = 0; i < folders.Length; i++)
            {
                if (!string.IsNullOrEmpty(folders[i]))
                {
                    ReportingService2010.CatalogItem[] foundItems = null;
                    condition.Values = new string[] { folders[i] };
                    rsService.FindItems(trusteduserHeader
                                        , parentFolderPath
                                        , ReportingService2010.BooleanOperatorEnum.And
                                        , new ReportingService2010.Property[0]
                                        , conditions
                                        , out foundItems);

                    if (foundItems == null || (foundItems != null && foundItems.Count() == 0))
                    {
                        ReportingService2010.CatalogItem linkedFolder = new ReportingService2010.CatalogItem();
                        rsService.CreateFolder(trusteduserHeader
                                               , folders[i]
                                               , parentFolderPath
                                               , new ReportingService2010.Property[0]
                                               , out linkedFolder
                                               );
                    }
                    parentFolderPath = parentFolderPath.TrimEnd('/') + @"/" + folders[i];
                }
            }
        }
Exemplo n.º 5
0
        private void CreateLinkedReport(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode
                                        , HttpClientCredentialType ReportHttpClientCredentialType
                                        , string ReportFolder, string ReportName
                                        , string LinkedReportPath
                                        , ReportingService2010.Property[] LinkedReportProperties
                                        , XElement xLinkedReportParameters
                                        //, string ParameterLanguage
                                        )
        {
            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)))
            {
                ReportingService2010.TrustedUserHeader trusteduserHeader;
                ReportExecution2005.TrustedUserHeader  userHeader;
                GetHeaders(UserName, UserPassword, rsService, null, 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.TrimStart('/').TrimEnd('/') };
                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)
                        {
                            string parentReportPath = item.Path;
                            try
                            {
                                string linkedReportName       = LinkedReportPath.Substring(LinkedReportPath.LastIndexOf('/') + 1).TrimStart('/').TrimEnd('/');
                                string linkedReportFolderPath = LinkedReportPath.Substring(0, LinkedReportPath.LastIndexOf('/')).TrimEnd('/');
                                CheckLinkedFolderExists(rsService, trusteduserHeader, condition, conditions, linkedReportFolderPath);
                                ReportingService2010.CatalogItem[] foundLinkedItems = null;
                                condition.Values = new string[] { linkedReportName };
                                rsService.FindItems(trusteduserHeader
                                                    , linkedReportFolderPath
                                                    , ReportingService2010.BooleanOperatorEnum.And
                                                    , new ReportingService2010.Property[0]
                                                    , conditions
                                                    , out foundLinkedItems);

                                if (foundLinkedItems == null || (foundLinkedItems != null && foundLinkedItems.Count() == 0))
                                {
                                    rsService.CreateLinkedItem(trusteduserHeader
                                                               , linkedReportName
                                                               , linkedReportFolderPath
                                                               , parentReportPath
                                                               , LinkedReportProperties);
                                }
                                if (xLinkedReportParameters != null)
                                {
                                    //// List of properties to copy from parent to linked reports. ???
                                    //var requestedProperties = new ReportingService2010.Property[] {
                                    //    new ReportingService2010.Property { Name = "PageHeight" },
                                    //    new ReportingService2010.Property { Name = "PageWidth" },
                                    //    new ReportingService2010.Property { Name = "TopMargin" },
                                    //    new ReportingService2010.Property { Name = "BottomMargin" },
                                    //    new ReportingService2010.Property { Name = "LeftMargin" },
                                    //    new ReportingService2010.Property { Name = "RightMargin" }
                                    //};

                                    IEnumerable <XElement> linkedReportParams = xLinkedReportParameters.Descendants("Param");
                                    if (linkedReportParams.Count() > 0)
                                    {
                                        List <ReportingService2010.ItemParameter> ItemParamsList = new List <ReportingService2010.ItemParameter>();
                                        foreach (var linkedReportParam in linkedReportParams)
                                        {
                                            string defaultValues = linkedReportParam.Attribute("DefaultValues").Value;
                                            if (!string.IsNullOrEmpty(defaultValues))
                                            {
                                                ReportingService2010.ItemParameter[] parentReportParams = null;
                                                rsService.GetItemParameters(trusteduserHeader
                                                                            , parentReportPath
                                                                            , null
                                                                            , false, null, null, out parentReportParams);

                                                bool paramExists = false;
                                                ReportingService2010.ItemParameter ip = new ReportingService2010.ItemParameter();
                                                ip.Name = linkedReportParam.Attribute("Name").Value;
                                                foreach (var parentReportParam in parentReportParams)
                                                {
                                                    if (parentReportParam.Name == ip.Name)
                                                    {
                                                        ip.AllowBlank          = parentReportParam.AllowBlank;
                                                        ip.MultiValue          = parentReportParam.MultiValue;
                                                        ip.Nullable            = parentReportParam.Nullable;
                                                        ip.Prompt              = parentReportParam.Prompt;
                                                        ip.PromptUser          = parentReportParam.PromptUser;
                                                        ip.PromptUserSpecified = parentReportParam.PromptUserSpecified;
                                                        paramExists            = true;
                                                        break;
                                                    }
                                                }
                                                if (paramExists)
                                                {
                                                    ip.DefaultValues = defaultValues.Split(',');
                                                    if (linkedReportParam.Attribute("Hide") != null &&
                                                        linkedReportParam.Attribute("Hide").Value.ToLower() == "true")
                                                    { //hide the paramerter using combination of parameters. There is no Hide property which reflects UI Hide checkbox
                                                        ip.PromptUser          = false;
                                                        ip.PromptUserSpecified = false;
                                                        ip.Prompt = null;
                                                    }
                                                    ItemParamsList.Add(ip);
                                                }
                                            }
                                        }
                                        rsService.SetItemParameters(trusteduserHeader, LinkedReportPath, ItemParamsList.ToArray());
                                    }
                                }
                            }
                            catch (SoapException ex)
                            {
                                LogMessage("Not able to create linked report " + LinkedReportPath + " Error: " + ex.Message);
                                throw;
                            }

                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 6
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;
                            }
                        }
                    }
                }
        }