SSRS -SQL Server Reporting Server
SQL Server Reporting Services provides access to the full functionality via Report Server Web service. The Web service uses Simple Object Access Protocol (SOAP) over HTTP and acts as a communications interface between client programs and the report server.
Here is the URL to access Reporting Server Web Service.
http://<YourServerName>/reportserver/reportservice.asmx
when your browse the Reporting Server Web Service you get the List of Methods which exposed.
Using this Reporting Service WebMethod i am going to call reports and Send as PDF format as Email Attachment.
Architecture Diagram – Accessing SSRS Web Service.
Accessing Report with Parameters and Saving as PDF format.
public static bool GetReportasPDF(string reportParameterName, string reportParameterValue,string reportPath)
{
string showHideToggle = null;
string encoding;
string mimeType;
// Read Report server Credentials
string userId = ConfigurationManager.AppSettings.Get(“ReportServerUser”);
string password = ConfigurationManager.AppSettings.Get(“RportServerPassWord”);
string domain = ConfigurationManager.AppSettings.Get(“ReportServerDomain”);
string reportFormat = ConfigurationManager.AppSettings.Get(“ReportFormatType”);
// Create Reporting Server Web Service Proxy class.
ReportingService rs = new ReportingService();
//NetworkCredential nwc = new NetworkCredential(“Sreeni”, “Gandhi”, “INDIA”);
// Set the Credentials
NetworkCredential nwc = new NetworkCredential(userId.Trim (), password.Trim (), domain.Trim ());
rs.Credentials = nwc;
// Set the Report Render arguments.
byte[] result = null;
//string reportPath = reportPath ;
string format = “PDF”;
string historyID = null;
string devInfo = null;
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = reportParameterName.Trim();
parameters[0].Value = reportParameterValue.Trim();
DataSourceCredentials[] credentials = null;
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;
SessionHeader sh = new SessionHeader();
rs.SessionHeaderValue = sh;
try
{
result = rs.Render(reportPath, format, historyID, “<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>”, parameters, credentials,
showHideToggle, out encoding, out mimeType, out reportHistoryParameters, out warnings,
out streamIDs);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.OuterXml);
StreamWriter sw = new StreamWriter(“C:\\ReportServerError.XML”);
sw.Write(e.Detail.OuterXml);
sw.Flush();
sw.Close();
return false;
}
// Write the contents of the report to an PDF file.
try
{
FileStream stream = File.Create(@”c:\Reports\”+reportParameterValue.Trim()+”.PDF”, result.Length);
stream.Write(result, 0, result.Length);
stream.Close();
return true;
}
catch (Exception e)
{
return false;
}
}

Leave a comment