c# - 在没有报表查看器的情况下将 SSRS 报表嵌入网页

标签 c# reporting-services ssrs-2008

我有一个用 VS2008 和 C# 编写的现有 Web 应用程序,我需要在其中将 SSRS 报告嵌入到网页中。数据库/SSRS 服务器位于异地并在防火墙后面,只能通过单独的 Web 服务器框的 IP 访问。数据库框正在运行 SQL Server 2008R2。 我无法使用 Report Viewer 控件作为解决方案。

我已经尝试了 SSRS 网络服务和 URL 访问。使用 Web 服务在调用 LoadReport 和/或 Render 方法时会引发错误。使用 URL 访问会生成报告项路径的错误。我尝试了许多不同的代码示例和方法来解决这个问题,但没有成功。有没有人有我可以用来让它工作的工作代码示例?

理想情况下,我希望通过某种方式从调用中返回 HTML,然后我可以将其放入 DIV 标记或 iframe 中。

最佳答案

Here is a sample it is working for me

Web config ...

<!-- Reporting -->
        <add key="ReportingUserName" value="xxxxx\xxxx" />
        <add key="ReportingPassword" value="xxxxxxxxx" />
        <add key="ReportingDomain" value="xxxxxxx" />


     <endpoint address="http://xxxxxx/ReportServer/ReportExecution2005.asmx" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfig" contract="SSRS.ReportExecutionServiceSoap" name="ReportExecutionServiceSoap" />

     <!-- Binding for Reporting Services over HTTP -->
            <binding name="basicHttpBindingConfig" allowCookies="true" maxReceivedMessageSize="52428800" sendTimeout="00:10:00">
              <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>

outputType ReportFormat i.e, Pdf,Image,Excel,Ffd

deviceInfo contains the XML string for reporting services based on the ReportFormat

reportPath contains report path on SSRS server "/xxx/datarecord-Table"

  private SsrsResponse ExecuteSsrsReport(string reportPath, IEnumerable<KeyValuePair<string, string>> parameters,
        string outputType, string deviceInfo)
    {
        using (var rs = new ReportExecutionServiceSoapClient())
        {
            if (rs.ClientCredentials != null)
            {
                rs.ClientCredentials.Windows.ClientCredential = GetReportingCredentials();
                rs.ClientCredentials.Windows.AllowedImpersonationLevel =
                    System.Security.Principal.TokenImpersonationLevel.Impersonation;
            }

            byte[] result;
            Warning[] warnings;
            string[] streamIds;

            ParameterValue[] parameterValues =
                parameters.Select(p => new ParameterValue { Name = p.Key, Value = p.Value }).ToArray();

            ExecutionInfo execInfo;
            ServerInfoHeader serverInfoHeader;

            ExecutionHeader execHeader =
                rs.LoadReport(null, reportPath, null, out serverInfoHeader, out execInfo);
            rs.SetExecutionParameters(execHeader, null, parameterValues, "en-us", out execInfo);

            string extension, mimeType, encoding;
            rs.Render(execHeader, null, outputType, deviceInfo,
                out result, out extension, out mimeType, out encoding, out warnings, out streamIds);

            return new SsrsResponse(result, extension, mimeType, encoding);
        }
    }

private NetworkCredential GetReportingCredentials()
{
    return new NetworkCredential(
        ConfigurationManager.AppSettings["ReportingUserName"],
        ConfigurationManager.AppSettings["ReportingPassword"],
        ConfigurationManager.AppSettings["ReportingDomain"]
    );
}

关于c# - 在没有报表查看器的情况下将 SSRS 报表嵌入网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20218281/

相关文章:

c# - 在组合框中滑动文本

reporting-services - 如何拆分全名字段(报表生成器)

ssrs-2008 - 排除SSRS报告的 "date/time"参数中的时间

reporting-services - 负数的 SSRS 格式

c# - PowerShell - X509Certificates.X509Store 获取所有证书?

c# - 无法正确实现对象属性值与控件属性值的绑定(bind)

c# - OWIN OpenID 连接授权无法授权安全 Controller /操作

reporting-services - 有没有人想出一种以大于 96ppi 的分辨率呈现 Reporting Services 报告的方法?

reporting-services - SSRS - 更改 "View Report"按钮的位置

reporting-services - 日期时间字段 SSRS 之间的时差