ActiveReports 8 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Common Walkthroughs > Web > Document Web Service |
With ASP.NET and ActiveReports, 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 as a byte array.
This walkthrough is split up into the following activities:
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 as a byte array.
To create an ASP.NET Web Service project
To write the code to create the Web Method
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 |
To write the code in C#
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
To publish the Document Web Service
Note: Get the SiteName from the Internet Information Services Manager. |
To check the configuration in IIS
For information on consuming the Document Web Service in a viewer, see Document Windows Application.