首页 > 解决方案 > 如何从 SSIS 包中调用 SSRS Soap?

问题描述

我正在处理来自 SQL Server 的数据,我会将其转换为文本文件,然后上传到 SSRS 文件夹。

我尝试使用 Web 服务任务组件,但它失败了。

知道我该如何解决这个问题吗?

标签: reporting-servicesssis

解决方案


我在这里找到了脚本任务中的代码以及如何连接到 SSRS 并上传文件的解决方案。这是一种接受字节数组并使用用于运行 ssis 包的默认凭据上传到 SSRS 的方法,当然,该凭据还应该可以访问 ssrs 或您打算上传文件的 ssrs 中的特定文件夹。

protected bool UploadFile(byte[] data, string description)
    {


        var result = false;
        try
        {
            if (data != null)
            {
                var fileName = string.Format("{0}_{1}_{2}{3}.zip", ZipPrefix, TargetDate, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"));
                var prefix = string.Format("{0}_{1}", ZipPrefix, TargetDate);

                ServiceManager.ReportingService2010 rs = new ServiceManager.ReportingService2010
                {
                    Url = ServiceUrl,
                    RequestEncoding = Encoding.UTF8,
                };

                rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

                ServiceManager.Property[] properties = {
                    new ServiceManager.Property() { Name = "MimeType", Value = "application/zip" }
                    ,new ServiceManager.Property(){ Name ="Description", Value = description}
                };

                var listItems = rs.ListChildren(SSRSFolder, false);

                //var a = string.Join(", ", listItems.Select(x => x.Name));
                //MessageBox.Show(a);

                foreach (var item in listItems)
                {
                    if (item.Name.Contains(prefix))
                    {
                        rs.DeleteItem(item.Path);
                    }
                }

                rs.CreateCatalogItem("Resource", fileName, SSRSFolder, false, data, properties, out ServiceManager.Warning[] warnings);

                result = true;
            }
        }
        catch (Exception e)
        {
            ErrorMessage = string.Format("Upload Error : {0}", e.Message);

            Dts.Log(e.Message, 1, null);
            throw new Exception(e.Message);
        }

        return result;
    }
    #endregion

请注意,我们需要向 SSRS Soap 添加服务引用。


推荐阅读