从 SSIS 脚本包中调用的 SSRS 报告将文件另存为 PDF 时出错

Error when file is saved as a PDF from an SSRS report called within an SSIS script package

我正在尝试使用在 SSIS 脚本任务中调用的 HTTP 连接下载 PDF 格式的 SSRS 报告。我收到错误 "could not open because it is either not a supported file type or because the file has been damaged."。最终目标是仅将 SSRS 报告保存在以 PDF 文件形式存储在变量 "AEIOutputStagingFileFullPath" 中的文件夹位置。这是 SSIS 脚本任务中的实际代码

   protected void SaveFile(string url, string localpath)
    {
        System.Net.HttpWebRequest loRequest;
        System.Net.HttpWebResponse loResponse;
        System.IO.Stream loResponseStream;
        System.IO.FileStream loFileStream = new System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
        byte[] laBytes = new byte[257];
        int liCount = 1;
        try
        {
            loRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
            loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
            loRequest.Timeout = 600000;
            loRequest.Method = "GET";
            loResponse = (System.Net.HttpWebResponse)loRequest.GetResponse();
            loResponseStream = loResponse.GetResponseStream();
            while (liCount > 0)
            {
                liCount = loResponseStream.Read(laBytes, 0, 256);
                loFileStream.Write(laBytes, 0, liCount);
            }
            loFileStream.Flush();
            loFileStream.Close();
        }
        catch (Exception ex)
        {
        }
    }

    public void Main()
    {
        ConnectionManager conn = Dts.Connections["AccountSTP_HTTPCon"];
        HttpClientConnection httpConn = new HttpClientConnection(conn.AcquireConnection(null));
        string outputSTPpdf = Dts.Variables["User::AEIOutputStagingFileFullPath"].Value.ToString();
        string pdfUrl = httpConn.ServerURL = @"http://vwdsrsdba0001/reports/report/TGAP/AccountChanges_STP&rs:Command=Render&rs:Format=PDF&rc:Toolbar=False";

        SaveFile(pdfUrl, outputSTPpdf);



        Dts.TaskResult = (int)ScriptResults.Success;
    }

我使用 webClient 来执行此操作:

        using (WebClient wc = new WebClient())
        {
            bool retry = true;
            int retryCt = 0;

            wc.Credentials = new System.Net.NetworkCredential([insert user],[insert password]);

            while (retry)
            {
                try
                {
                    wc.DownloadFile(@"http://[insert server]/Reportserver?/[insert folder]/[insert report name]&rs:Command=Render&rs:Format=PDF&rc:Toolbar=False&[query string of params are optional]"
                                    , filepathName);
                    retry = false;
                }
                catch
                {
                    retryCt++;
                    if (retryCt >= 10) { retry = false; }
                }
            }
        }