将SSRS 2016报告嵌入到没有iFrame的其他网页中?

时间:2016-03-07 09:13:14

标签: reporting-services ssrs-2016

报表服务2016(目前仅作为技术预览版提供)附带大升级,包括HTML5渲染和合规性。请参阅:https://msdn.microsoft.com/en-us/library/ms170438.aspx

我的愿望是使用纯模式将SSRS 2016报告嵌入到另一个网页中(没有Sharepoint或aspx,只有纯HTML5)。 这样做的传统方式是使用iFrame。 这是一个中途好的方法,因为它可以删除工具栏,隐藏参数等但仍然最终失去对文档的大量控制。这是来自不同域的跨站点实现,因此我无法操纵所包含的iFrame文档。

是否存在以“本机”方式嵌入报表元素的官方方式? 我可以想象一个像rs:Format=REPORTDIV这样的URL参数选项,它为我提供了一个html元素。

我还尝试将报告作为图像(rs:Format=IMAGE&rc:OutputFormat=PNG)获取,但生成的PNG在报告元素周围有一个巨大的白框(即使在报表生成器中将背景设置为透明),这是不行的。

1 个答案:

答案 0 :(得分:3)

这应该有效。它应该在环境之外工作,并且它嵌入来自内存的图像而不是从数据库中获取它们

// Create service instance
            ReportExecutionServiceSoapClient rsExec = new ReportExecutionServiceSoapClient(binding, endpoint);
            rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            rsExec.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

            ReportingServices.Extension[] extentions = null;
            ReportingServices.TrustedUserHeader trustedUserHeader = new ReportingServices.TrustedUserHeader();
            rsExec.ListRenderingExtensions(trustedUserHeader, out extentions);
            string reportPath = "/Untitled";
            ExecutionInfo execInfo = new ExecutionInfo();
            ExecutionHeader execHeader = new ExecutionHeader();
            ReportingServices.ServerInfoHeader serverInfo = new ReportingServices.ServerInfoHeader();
            string historyID = null;

            rsExec.LoadReport(trustedUserHeader, reportPath, historyID, out serverInfo, out execInfo);

            //Get execution ID
            execHeader.ExecutionID = execInfo.ExecutionID;
            string deviceInfo = null;
            string extension;
            string encoding;
            string mimeType;
            ReportingServices.Warning[] warnings = new ReportingServices.Warning[1];
            warnings[0] = new ReportingServices.Warning();
            string[] streamIDs = null;

            string format = "HTML5";
            Byte[] result;
            rsExec.Render(execHeader, trustedUserHeader, format, deviceInfo, out result, out extension, out mimeType, out encoding, out warnings, out streamIDs);

            var report = Encoding.UTF8.GetString(result);
            int streamIdCount = streamIDs.Length;
            Byte[][] imageArray = new Byte[streamIdCount][];
            String[] base64Images = new String[streamIdCount];
            for (int i = 0; i <= streamIdCount - 1; i++)
            {
                Byte[] result2;
                string streamId = streamIDs[i];
                rsExec.RenderStream(execHeader, trustedUserHeader, format, streamId, deviceInfo, out result2, out encoding, out mimeType);
                imageArray[i] = result2;
                base64Images[i] = Convert.ToBase64String(result2);
                string replace = string.Format("https://<reportserver>/ReportServer?%2FUntitled&rs%3ASessionID={0}&rs%3AFormat={1}&rs%3AImageID={2}", execInfo.ExecutionID, format, streamId);
                string src = string.Format("data:{0};charset=utf-8;base64, {1}", mimeType, base64Images[i]);
                report = report.Replace(replace, src);
            }