在没有报表查看器的情况下将SSRS报表嵌入到网页中

时间:2013-11-26 13:23:52

标签: c# reporting-services ssrs-2008

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

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

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

2 个答案:

答案 0 :(得分:0)

  

这是一个为我工作的样本

     

网络配置......

<!-- 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,即Pdf,Image,Excel,Ffd

     

deviceInfo包含用于报告服务的XML字符串   ReportFormat

     

reportPath包含SSRS服务器上的报告路径“/ 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"]
    );
}

答案 1 :(得分:0)

尝试在iframe中调用相同的报告URI。