简体   繁体   English

在没有Report Viewer的情况下将SSRS报告嵌入网页

[英]Embed SSRS report into web page without Report Viewer

I have an existing web application written in VS2008 & C# where I need to embed an SSRS report into a web page. 我有一个用VS2008和C#编写的现有Web应用程序,需要将SSRS报告嵌入到网页中。 The database/SSRS server is offsite and behind a firewall and only accessible via IP from the separate web server box. 数据库/ SSRS服务器不在现场且在防火墙后面,只能通过IP从单独的Web服务器框中访问。 The database box is running SQL Server 2008R2. 数据库框正在运行SQL Server 2008R2。 I cannot use the Report Viewer control as a solution. 我不能将Report Viewer控件用作解决方案。

I have tried both the SSRS web service and URL access. 我已经尝试了SSRS Web服务和URL访问。 Using the web service throws errors when calling LoadReport and/or Render methods. 调用LoadReport和/或Render方法时,使用Web服务会引发错误。 Using URL access generates an error for the path of the report item. 使用URL访问会为报告项目的路径生成错误。 I have tried many different code samples and methods to resolve this with no luck. 我已经尝试了许多不同的代码示例和方法来解决这个问题,但是没有运气。 Does anyone have a working code sample that I can use to get this to work? 有人有可以使用的工作代码示例吗?

Ideally I'd like some way to have HTML returned from a call that I can then place into a DIV tag or iframe. 理想情况下,我希望以某种方式从调用返回HTML,然后将其放入DIV标签或iframe中。

Here is a sample it is working for me 这是一个为我工作的样品

Web config ... Web配置...

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

deviceInfo contains the XML string for reporting services based on the ReportFormat deviceInfo包含用于基于ReportFormat的报告服务的XML字符串

reportPath contains report path on SSRS server "/xxx/datarecord-Table" 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"]
    );
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM