Hi,
Just sharing a sample code that uses ReportExecution2005 web service of SSRS 2008, and generates pdf of one of the custom reports deployed in CRM.
Here we are also passing value to one of the report parameter.
<br />
// Add web reference to following service<br />
// http://server/reportserver/ReportExecution2005.asmx</p>
<p>ReportExecutionService rs = new ReportExecutionService();<br />
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;</p>
<p>// Render arguments<br />
byte[] result = null;<br />
// Get the report path from the report server<br />
// http://reportserver/Reports/Pages/Folder.aspx?ViewMode=Detail</p>
<p>string reportPath = "/MyOrg_MSCRM/CustomReports/{837a8e7e-d949-e111-996a-00155d2a49c7}";<br />
string format = "PDF";<br />
string historyID = null;</p>
<p>string encoding;<br />
string mimeType;<br />
string extension;<br />
Warning[] warnings = null;<br />
string[] streamIDs = null;</p>
<p> ExecutionHeader execHeader = new ExecutionHeader();<br />
rs.ExecutionHeaderValue = execHeader;<br />
rs.LoadReport(reportPath, historyID);</p>
<p>// Set DataSource Credentials<br />
// the user name is your userid and the password is the id of the organization<br />
// get more info here<br />
// http://ronaldlemmen.blogspot.com/2009/01/log-in-name-and-password-required-by.html<br />
DataSourceCredentials datasetCredential = new DataSourceCredentials();<br />
datasetCredential.DataSourceName = "DataSource1";<br />
datasetCredential.UserName = "F45D4E20-44DE-E011-8A08-005056860004";<br />
datasetCredential.Password = "D0E60C19-44DE-E011-8A08-005056860004";</p>
<p>// Set Report Parameter values<br />
ParameterValue[] myPVArray = new ParameterValue[1];<br />
ParameterValue myPV = new ParameterValue();<br />
myPV.Name = "ReportParameter1";<br />
myPV.Value = "True";<br />
myPVArray[0] = myPV;</p>
<p>rs.SetExecutionParameters(myPVArray, "en-us");</p>
<p> DataSourceCredentials[] credentials = new DataSourceCredentials[1];<br />
credentials[0] = datasetCredential;<br />
rs.SetExecutionCredentials(credentials);</p>
<p>result = rs.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs);</p>
<p>Response.Clear();<br />
MemoryStream ms = new MemoryStream(result);<br />
Response.ContentType = "application/pdf";<br />
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf");<br />
Response.Buffer = true;<br />
ms.WriteTo(Response.OutputStream);<br />
Response.End();<br />
Bye.







