C1ReportViewer Task-Based Help > Loading Documents into C1ReportViewer > Creating and Loading Reports Dynamically (Silverlight) |
Another fairly common scenario is dynamic report creation. In this case, you would configure the report server to allow access from your application server, and would use a Web service similar to the one described in the Loading Documents from Files on the Server topic to obtain the report stream directly from the report server (instead of loading it from a file).
The specific steps involved depend on the specific report server you are using. To dynamically obtain a PDF report from a Microsoft SQL Server Reporting Services server, for example, you would modify the Web service listed in the Loading Documents from Files on the Server topic as follows:
Visual Basic |
Copy Code
|
---|---|
<ServiceContract([Namespace] := "")> _ <AspNetCompatibilityRequirements(RequirementsMode := AspNetCompatibilityRequirementsMode.Allowed)> _ Public Class ReportsService <OperationContract> _ Public Function GetReportStream(reportName As String) As Byte() Dim reportServer As String = "YOUR REPORT SERVER NAME" Dim url = String.Format("http://{0}/ReportServer?/{1}&rs:Format=PDF", reportServer, reportName.Replace(" "C, "+"C)) Dim wc = New System.Net.WebClient() wc.UseDefaultCredentials = True Dim stream = wc.OpenRead(url) Dim ms = New MemoryStream() Dim buf = New Byte(64 * 1024 - 1) {} While True Dim read As Integer = stream.Read(buf, 0, buf.Length) If read = 0 Then Exit While End If ms.Write(buf, 0, read) End While ms.Flush() Return ms.ToArray() End Function End Class |
C# |
Copy Code
|
---|---|
[ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class ReportsService { [OperationContract] public byte[] GetReportStream(string reportName) { string reportServer = "YOUR REPORT SERVER NAME"; var url = string.Format("http://{0}/ReportServer?/{1}&rs:Format=PDF", reportServer, reportName.Replace(' ', '+')); var wc = new System.Net.WebClient(); wc.UseDefaultCredentials = true; var stream = wc.OpenRead(url); var ms = new MemoryStream(); var buf = new byte[64 * 1024]; for (; ; ) { int read = stream.Read(buf, 0, buf.Length); if (read == 0) break; ms.Write(buf, 0, read); } ms.Flush(); return ms.ToArray(); } } |
As you can see, the difference is minimal. This approach still allows you to specify the report caching policy on the report server, so there is no loss of performance or scalability.