[英]Embed SSRS report into web page without Report Viewer
我有一個用VS2008和C#編寫的現有Web應用程序,需要將SSRS報告嵌入到網頁中。 數據庫/ SSRS服務器不在現場且在防火牆后面,只能通過IP從單獨的Web服務器框中訪問。 數據庫框正在運行SQL Server 2008R2。 我不能將Report Viewer控件用作解決方案。
我已經嘗試了SSRS Web服務和URL訪問。 調用LoadReport和/或Render方法時,使用Web服務會引發錯誤。 使用URL訪問會為報告項目的路徑生成錯誤。 我已經嘗試了許多不同的代碼示例和方法來解決這個問題,但是沒有運氣。 有人有可以使用的工作代碼示例嗎?
理想情況下,我希望以某種方式從調用返回HTML,然后將其放入DIV標簽或iframe中。
這是一個為我工作的樣品
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,即Pdf,Image,Excel,Ffd
deviceInfo包含用於基於ReportFormat的報告服務的XML字符串
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.