I have an existing web application written in VS2008 & C# where I need to embed an SSRS report into a web page. The database/SSRS server is offsite and behind a firewall and only accessible via IP from the separate web server box. The database box is running SQL Server 2008R2. I cannot use the Report Viewer control as a solution.
I have tried both the SSRS web service and URL access. Using the web service throws errors when calling LoadReport and/or Render methods. Using URL access generates an error for the path of the report item. 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.
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 ie, 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"]
);
}
尝试在iframe中调用报表的相同URI。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.