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.
Microsoft SQL Server Reporting Service (SSRS) is an enterprise reporting server corporations use to develop, manage and distribute reports to the business. Reporting Services Web Service is the web-based capability, which uses Extensible Markup Language (XML), a standard for porting documents, and Simple Object Access Protocol (SOAP), a web service or protocol to exchange information on the web. SOAP is a web alternative to Hypertext Transfer Protocol (HTTP), a long-term standard used on the web. To access Reporting Services Web Services you will need to create an application in Microsoft Visual Studio.
LikeLike
Hi, do you have any idea why it show System.Web.Services.Protocols.SoapException: The data source ‘MSCRM_FetchDataSource’ cannot be found. error when running the code above? FYI, I am able to generate the report in the Report Manager but running the code above failed. I tried published to external user but no luck.
LikeLike
Hi,
Thanks! This works very well.
However, how do I pass a guid as parameter to the report, e.g. an accountid if I want to execute the report for a specific Account only?
LikeLike
Use custom objects for RDL – SSRS (Reporting Services)
http://stackoverflow.com/questions/33760416/use-custom-objects-for-rdl-ssrs-reporting-services
DataSet as parameter RDL ?
LikeLike
Thanks Nishant for this article!!
Just adding comments for the below 2 lines :
datasetCredential.UserName = “F45D4E20-44DE-E011-8A08-005056860004”; //Guid of user
datasetCredential.Password = “D0E60C19-44DE-E011-8A08-005056860004”; //Guid of organisation
LikeLike