Hi,
I want to post information on rendering reports within your web application without having it prompt for a user name and password.
Microsoft posts step-by-step instructions here, http://support.microsoft.com/?kbid=875447, so I won’t repost what is there, but I want to point out a couple gotchas that our clients have experienced.
Gotcha #1:
Be sure to consume the correct web service. And, don’t forget to use https:// if Reporting Services is configured to use a SSL Certificate.
SQL Server 2000 Reporting Services:
http://ReportServerName/ReportServer/ReportService.asmx
SQL Server 2005 Reporting Services:
http://ReportServerName/ReportServer/ReportExecution2005.asmx
Gotcha #2:
When passing credentials, if you are using a domain account, be sure to add it within the code behind page.
ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = new System.Net.NetworkCredential("user", "password", “domain”);
In the end your code behind page should look similar to this:
using com.domain.ssrs;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RenderTest_Click(object sender, EventArgs e)
{
ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = new System.Net.NetworkCredential("user", "password", “domain”);
// Render arguments
byte[] result = null;
string reportPath = "/My Reports/test/test";
string format = "PDF";
string historyID = null;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
result = rs.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs);
Response.ClearContent();
Response.AppendHeader("content-length", result.Length.ToString());
Response.ContentType = "application/pdf";
Response.BinaryWrite(result);
Response.Flush();
Response.Close();
}
}