Microsoft KB Archive/875447

= How to create a sample application that uses the Reporting Services SOAP APIs to render a report to a selected file format on a Web page =

Article ID: 875447

Article Last Modified on 4/3/2007

-

APPLIES TO


 * Microsoft SQL Server 2000 Reporting Services
 * Microsoft SQL Server 2005 Reporting Services

-





INTRODUCTION
This step-by-step article describes how to create a sample Microsoft ASP.NET Web application that uses the Microsoft SQL Server 2000 Reporting Services SOAP APIs and the Microsoft SQL Server 2005 Reporting Services SOAP APIs to perform the following:
 * Render a report that is deployed on a report server to a supported file format, such as the .pdf file format.
 * Open the rendered report on a Web page without saving the file that corresponds to the rendered report on your computer.

Note To render the report to the requested file format by using the ASP.NET Web application, the program that supports the file format must be installed on your computer. For example, to view a report that is rendered to the .pdf file format, Adobe Acrobat Reader must be installed on your computer.



MORE INFORMATION
You can generate a report by using Reporting Services, and you can view the report by using Report Manager. Report Manager is included with Reporting Services. By using Report Manager, you can render your report to different file formats that are supported by Reporting Services. To render a report to a specific file format, follow these steps:
 * 1) Start Report Manager.
 * 2) Locate your report in Report Manager, and then click the report to preview your report.
 * 3) In the Select a format list, click the file format that you want to use to render your report, and then click Export.

After you click Export in Report Manager, the File Download dialog box opens. The File Download dialog box provides an option to save the rendered report on your computer. Even if you open the report without saving the report, a file that corresponds to the rendered report is created on your computer.

If you want to render a report to the requested file format without creating the file that corresponds to the rendered report on your computer, you can use the Render method in the Reporting Services SOAP APIs. For more information about the Render method for SQL Server 2000 Reporting Services, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/aa225827(SQL.80).aspx

For more information about the Render method for SQL Server 2005 Reporting Services, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

To create a sample ASP.NET Web application to render a report that is deployed on a report server to the requested file format and to open the rendered report on a Web page by using the Reporting Services SOAP APIs, follow these steps.

Note This sample application renders the Company Sales sample report to the .pdf file format. Therefore, you must make sure that the Company Sales sample report is deployed on your report server in the SampleReports folder. You must also make sure that a program such as Adobe Acrobat Reader is installed on your computer before you run this application.

Use Microsoft Visual Studio .NET 2003 to render the Company Sales sample report that is included in SQL Server 2000 Reporting Services or SQL Server 2005 Reporting Services
 Start Microsoft Visual Studio .NET 2003. On the File menu, click New, and then click Project. In the New Project dialog box, under Project Types, click Visual C# Projects. In the New Project dialog box, under Templates, click ASP.NET Web Application. In the Location box, type http:// /RenderCompanySales, and then click OK to create the project. Add a Web reference to the ReportService Web service. To do this, follow these steps:  On the Project menu, click Add Web Reference.</li> In the Add Web Reference dialog box, type http:// /ReportServer/ReportService.asmx in the URL box, and then click Go.</li> In the Web reference name box, type RSWebReference, and then click Add Reference.</li></ol> </li> In the left pane, under Toolbox, click Web Forms, and then double-click Button to add a button control to the Web form.</li> Set the properties of the button control by using the following information: <ul> (ID): RenderTest </li> Text: Render Report in PDF Format </li></ul> </li> On the View menu, click Code.</li>  Add the following code at the top of the code window: using RenderCompanySales.RSWebReference; </li>  Add the following method as the event handler of the click event for the RenderTest button in your code: private void RenderTest_Click(object sender, System.EventArgs e)       { RSWebReference.ReportingService rs = new RSWebReference.ReportingService; rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

Byte[] result;

string encoding; string mimetype; ParameterValue[] parametersUsed; Warning[] warnings; string[] streamids;

result = rs.Render(&quot;/SampleReports/Company Sales&quot;,&quot;PDF&quot;,null,null,null,null,null,out encoding,out mimetype,out parametersUsed,out warnings,out streamids); Response.ClearContent; Response.AppendHeader(&quot;content-length&quot;, result.Length.ToString); Response.ContentType = &quot;application/pdf&quot;; Response.BinaryWrite(result); Response.Flush; Response.Close; } </li> On the Debug menu, click Start to run the code.</li> On the WebForm1 Web page, click Render Report in PDF Format.</li></ol>

Use Microsoft Visual Studio 2005 to render the Company Sales sample report that is included in SQL Server 2005 Reporting Services
<ol> Start Microsoft Visual Studio 2005.</li> On the File menu, click New, and then click Web Site.</li> In the New Web Site dialog box, click ASP.NET Web Site under Visual Studio installed templates,</li> Click HTTP in the Location list, and then type http:// /RenderCompanySales in the box that is next to the Location list</li> <li>In the Language list, click Visual C#, and then click OK.</li> <li>Add a Web reference to the ReportService Web service. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Website menu, click Add Web Reference.</li> <li>In the Add Web Reference dialog box, type http:// /ReportServer/ReportExecution2005.asmx in the URL box, and then click Go.</li> <li>In the Web reference name box, type RSWebReference, and then click Add Reference.</li></ol> </li> <li>On the View menu, click Designer, and then add a Button control to the Web form.</li> <li>Set the properties of the Button control by using the following information: <ul> <li>(ID): RenderTest </li> <li>Text: Render Report in PDF Format </li></ul> </li> <li>On the View menu, click Code.</li> <li> Add the following line of code at the top of the code window: using RSWebReference; </li> <li> Add the following method as the event handler of the click event for the RenderTest button in your code. protected void RenderTest_Click(object sender, EventArgs e)   { ReportExecutionService rs = new ReportExecutionService; rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Render arguments byte[] result = null; string reportPath = &quot;/AdventureWorks Sample Reports/Company Sales&quot;; string format = &quot;PDF&quot;; 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(&quot;content-length&quot;, result.Length.ToString); Response.ContentType = &quot;application/pdf&quot;; Response.BinaryWrite(result); Response.Flush; Response.Close;

} </li> <li>On the Debug menu, click Start Debugging to run the code.</li> <li>On the Web page that Visual Studio 2005 opens, click Render Report in PDF Format.</li></ol>

<div class="references_section">