With ASP.NET and ActiveReports Developer, you can set up a Web Service that returns a report document which can be shown in a report viewer control.
This walkthrough illustrates how to create a Web Service that returns the contents of an ActiveReports Developer as a byte array.
This walkthrough is split up into the following activities:
- Creating an ASP.NET Web Service project
- Adding code to create the Web Method
- Testing the Web Service
- Publishing the Web Service
- Creating a virtual directory in IIS
Note: For the information on how to connect your report to data and how to create the report layout, please see Single Layout Reports (for a page report) or Basic Data Bound Reports (for a section report). |
When you have completed this walkthrough, you will have a Web Service that returns the contents of an ActiveReports Developer as a byte array.
To create an ASP.NET Web Service project
- From the File menu, select New Project.
- In the New Project dialog that appears, select ASP.NET Web Service Application.
- Change the name of the project.
- Click OK to open the new project in Visual Studio.
To write the code to create the Web Method
- On the Service.vb or Service.cs tab is the code view of the Service.asmx file.
- Replace the existing WebMethod and HelloWorld function with the following code.
To write the code in Visual Basic.NET
The following example demonstrates how you create the Web Method for a page report.
Visual Basic.NET code. REPLACE the existing WebMethod and function with this code. | Copy Code |
---|---|
<WebMethod( _ Description:="Returns a products report grouped by category")> _ Public Function GetProductsReport() As Byte() Dim rpt As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\PageReport.rdlx")) rpt.Run() Dim rdfe As New GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension Dim ms As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider rpt.Document.Render(rdfe, ms) Dim doc_rdf As New GrapeCity.ActiveReports.Document.SectionDocument doc_rdf.Load(CType(ms.GetPrimaryStream.OpenStream, System.IO.MemoryStream)) Return doc_rdf.Content End Function |
The following example demonstrates how you create the Web Method for a section report.
Visual Basic.NET code. REPLACE the existing WebMethod and function with this code. | Copy Code |
---|---|
<WebMethod( _ Description:="Returns a products report grouped by category")> _ Public Function GetProductsReport() As Byte() Dim rpt As New rptProducts() rpt.Run() Return rpt.Document.Content End Function |
The following example demonstrates how you create the Web Method for a page report.
C# code. REPLACE the existing WebMethod and function with this code. | Copy Code |
---|---|
[WebMethod(Description = "Returns a products report grouped by category")] public byte[] GetProductsReport() { GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\PageReport.rdlx")); rpt.Run(); GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension rdfe = new GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider ms = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider(); rpt.Document.Render(rdfe, ms); GrapeCity.ActiveReports.Document.SectionDocument doc_rdf = new GrapeCity.ActiveReports.Document.SectionDocument(); doc_rdf.Load((System.IO.MemoryStream)ms.GetPrimaryStream.OpenStream); return doc_rdf.Content; } |
The following example demonstrates how you create the Web Method for a section report.
C# code. REPLACE the existing WebMethod and function with this code. | Copy Code |
---|---|
[WebMethod(Description="Returns a products report grouped by category")] public Byte[] GetProductsReport() { rptProducts rpt = new rptProducts(); rpt.Run(); return rpt.Document.Content; } |
To test the Document Web Service
- Press F5 to run the project. The Service page appears in your browser.
- In the list of supported operations at the top, click GetProductsReport.
- Click the Invoke button to test the Web Service operation.
- If the test is successful, you will see the binary version of the contents of rptProducts.
To publish the Document Web Service
- In the Solution Explorer, right-click the project name and select Publish.
- In the Publish Web window that appears, enter locahost in the Service URL field and "SiteName"/WebService in the Site/application field.
Note: Get the SiteName from the Internet Information Services Manager. - Select the Mark an IIS application on destination option and click the OK button.
To check the configuration in IIS
- Open Internet Information Services Manager.
- In the Internet Information Services Manager window that appears, expand the tree view in the left pane until you see the Web Service you had added in the steps above.
- Right-click the Web Service select Manage Application then Browse.
- In the browser that appears, go to the Address bar and add \Service1 to the url.
For information on consuming the Document Web Service in a viewer, see Document Windows Application.