访问SSRS Reports
1, URL Access
string urlReport = "http://216.91.145.207/Reportserver?%2fDataRapRAFAdmin/AttestationHMPN&rs:Command=Render&rc:Parameters=false&rs:Format=HTML4.0&GMPI=50303";
this.rptContainer.Attributes["src"] = urlReport;
2, ReportViewer Control
private void DisplayReport()
{
Collection<RptParameter.ReportParameter> rptParam = new Collection<RptParameter.ReportParameter>();
rptParam.Add(new RptParameter.ReportParameter("GMPI", "50303"));
rptViewer.Attributes.Add("style", "margin-bottom:50px");
rptViewer.ServerReport.ReportServerUrl = new Uri("http://216.91.145.207/Reportserver");
rptViewer.ServerReport.ReportPath = "/DataRapRAFAdmin/AttestationHMPN";
rptViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials("Administrator","Ply2929","WORKGROUP");
rptViewer.ServerReport.SetParameters(rptParam);
rptViewer.ServerReport.Refresh();
}
/// <summary>
/// Local implementation of IReportServerCredentials
/// </summary>
public class ReportServerCredentials : IReportServerCredentials
{
private string _userName;
private string _password;
private string _domain;
public ReportServerCredentials(string userName, string password, string domain)
{
_userName = userName;
_password = password;
_domain = domain;
}
public WindowsIdentity ImpersonationUser
{
get
{
// Use default identity.
return null;
}
}
public ICredentials NetworkCredentials
{
get
{
// Use default identity.
return new NetworkCredential(_userName, _password, _domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
{
// Do not use forms credentials to authenticate.
authCookie = null;
user = password = authority = null;
return false;
}
}
3, Web Service Access
<%@ WebHandler Language="C#" class="ReportHandler" %>
using System;
using System.Web;
using System.Net;
using System.IO;
using rwrReports;
public class ReportHandler : IHttpHandler
{
private const string Report_Format = "PDF";
public void ProcessRequest(HttpContext context)
{
GenerateAttestationPDFStream(context);
}
private void GenerateAttestationPDFStream(HttpContext context)
{
string pindex = context.Request["GMPI"];
byte[] responseBuffer = null;
string msg = null;
string historyID = null;
string showHideToggle = null;
string encoding = null;
string mimetype = null;
string[] streamIDs = null;
string format = Report_Format;
string Report_Path = Lib.GetConfigData("Attestation_Report");
string devInfo = "";
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
ParameterValue[] reportParams = new ParameterValue[3];
ParameterValue pGMPI = new ParameterValue();
pGMPI.Name = "GMPI";
pGMPI.Value = pindex;
reportParams[0] = pGMPI;
ParameterValue pMethodID = new ParameterValue();
pMethodID.Name = "AttestationCreationMethodID";
pMethodID.Value = "2";
reportParams[1] = pMethodID;
ParameterValue pUserId = new ParameterValue();
pUserId.Name = "AttestationGenerationUser";
pUserId.Value = HttpContext.Current.Profile.UserName;
reportParams[2] = pUserId;
ReportingService rs = new ReportingService();
rs.Url = Lib.GetReportingServiceURL;
rs.Credentials = new NetworkCredential(Lib.GetRptServerUid, Lib.GetRptServerPwd, Lib.GetRptServerDomain);
try
{
responseBuffer = rs.Render(Report_Path, format, historyID, devInfo, reportParams, null, showHideToggle,
out encoding, out mimetype, out reportHistoryParameters,
out warnings, out streamIDs);
context.Response.Clear();
context.Response.ContentType = mimetype;
context.Response.BinaryWrite(responseBuffer);
context.Response.End();
}
catch (Exception ex)
{
msg = ex.Message;
if (ex.InnerException != null)
{
msg = msg + "<br/>"+ex.InnerException.ToString();
}
context.Response.Write("<div style=\"color:red;font-family:Verdana;font-size:22px\"><br/><span style=\"color:blue;text-align:left\">System Error:</span><br/><br/>" + msg + "<br/><br/><br/><br/><br/><center><a href=\"#\" onclick=\"window.close()\" > Close the Window </a></center></div>");
}
}
public bool IsReusable {
get {
return false;
}
}
}

浙公网安备 33010602011771号