This is a migrated thread and some comments may be shown as answers.

Silverlight WCF Telerik Reporting

4 Answers 190 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 2
B asked on 11 Dec 2012, 04:25 PM
Hi,

I set up a Telerik Reporting WCF Service, a silverlight client to show the report, created a report, succesfully added the WCF report service reference to the client, and verified that it is called. Everything works up to that part.

But how do I implement the methods of the IReportService interface? I can't find examples of what I'm supposed to do. Below is the code that I guessed so far from trial and error, but this gives a xaml error.

Is there an example of how to implement a WCF reporting service?
 
In specific the method: GetPage, what is the byte[]?The manual says "Gets or sets the Byte array that contains the current report page.", but is that in pdf format?

Regards,

Bayram

    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ReportService" in code, svc and config file together.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ReportService : IReportService
    {
        public void DoWork()
        {
        }
 
        private byte[] RenderToArray(string instanceID)
        {
            Telerik.Reporting.Processing.ReportProcessor reportProcessor =
                new Telerik.Reporting.Processing.ReportProcessor();
 
            //set any deviceInfo settings if necessary
            System.Collections.Hashtable deviceInfo =
                new System.Collections.Hashtable();
 
            Telerik.Reporting.InstanceReportSource instanceReportSource =
                new Telerik.Reporting.InstanceReportSource();
 
            instanceReportSource.ReportDocument = new PowerBrowser.Web.Modules.Reporting.ReportZakenDashboard();
 
            Telerik.Reporting.Processing.RenderingResult renderingResult =
                reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
 
            string fileName = renderingResult.DocumentName + "." + renderingResult.Extension;
            string path = System.IO.Path.GetTempPath();
            string filePath = System.IO.Path.Combine(path, fileName);
 
            byte[] result = new byte[renderingResult.DocumentBytes.Length];
            using (System.IO.MemoryStream fs = new System.IO.MemoryStream(result))
            {
                fs.Write(renderingResult.DocumentBytes, 0, renderingResult.DocumentBytes.Length);
            }
            return result;
        }
 
        public Telerik.Reporting.Service.PageInfo GetPage(string instanceID, int pageNumber)
        {
            PageInfo info = new PageInfo()
            {
                Buffer = RenderToArray(""),
                PageNumber = 1
            };
            return info;
        }
 
        public List<Parameter> GetReportParameters(string report, NameValueDictionary deviceInfo, NameValueDictionary parameters)
        {
            List<Parameter> reportParameters = new List<Parameter>();
            return reportParameters;
        }
 
        public IList<ReportInfo> ListAvailableReports()
        {
            ReportInfo info = new ReportInfo()
            {
                Description = "Mijn zaken",
                FullName = "Rapport - Mijn zaken",
                Name = "ReportZakenDashboard"
            };
            List<ReportInfo> reports = new List<ReportInfo>();
            reports.Add(info);
            return reports;
        }
 
        public IList<ExtensionInfo> ListRenderingExtensions()
        {
            List<ExtensionInfo> extensions = new List<ExtensionInfo>();
            ExtensionInfo info = new ExtensionInfo() { LocalizedName = "PDF", Name = "PDF" };
            extensions.Add(info);
            return extensions;
        }
 
        public RenderingResult Render(string format, string report, NameValueDictionary deviceInfo, NameValueDictionary parameters)
        {
            RenderingResult renderingResult = null;
            if (report == "ReportZakenDashboard")
            {
                renderingResult = new RenderingResult()
                {
                    DocumentBytes = new byte[] { },
                    DocumentName = "Test",
                    Extension = "PDF",
                };
            }
            return renderingResult;
        }
 
        public RenderingSessionInfo RenderAndCache(string format, string report, NameValueDictionary deviceInfo, NameValueDictionary parameters)
        {
            RenderingSessionInfo info = new RenderingSessionInfo()
            {
                PageCount = 1,
                DocumentName = "Mijn zaken",
                PageNumber = 1,
                Report = "ReportZakenDashboard"
            };
            return info;
        }
    }

4 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 14 Dec 2012, 02:57 PM
Hello Bayram,

Why do you avoid our implementation of IReportService? Generally the Telerik Reporting source code is available for download from your accounts download page and you can use them as reference. About your inquiry the PageInfo.Buffer is a rendered page.

Regards,
Peter
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
B
Top achievements
Rank 2
answered on 17 Dec 2012, 08:31 AM
Hi Peter,

I'm using the instructions on:
http://www.telerik.com/help/reporting/silverlight-report-viewer.html
which says: The Silverlight report viewer requires the Telerik Reporting WCF Service, so I also use these instructions: 
http://www.telerik.com/help/reporting/silverlight-wcf-service-overview.html

There it says:

The default Telerik Reporting WCF Service implementation uses ASP.NET Session in order to store various resources such as report pages and images. When ran out of web context (e.g. self-hosted service), it uses internal session storage. To make your own implementation, create your own service class derived from ReportServiceBase and override its GetState and SetState methods.


I asume "The default Telerik Reporting WCF Service" is what you mean by your implementation? But how do i get that working? There is no link to how to set that up.

Or is deriving from ReportServiceBase what you mean by your implementation?

What format is the rendered page? I can't get "HTML", "PDF" or "IMAGE" to work for example. I used the list here:
http://www.telerik.com/help/reporting/configuring-rendering-extensions.html

Tho rendering seems to work: the client doesn't understand the contents of the byte[], it seems to expect some other format?

Regards,

Bayram
0
B
Top achievements
Rank 2
answered on 17 Dec 2012, 11:05 AM

Hi Peter,

I got it to work using the demo sources, so this issue can be closed, thanks for your help.

Here are the steps I did:

1. Removed the ReportService.cs file so that just the ReportService.svc file remains containing 1 line:

<%@ServiceHost Service="Telerik.Reporting.Service.ReportService, Telerik.Reporting.Service, Version=6.2.12.1017, Culture=neutral, PublicKeyToken=A9D7983DFCC261BE" %>

2. Copied anything refering to Report from the Web.config file: endpoints, behaviours, connections. Replacing parts were needed:

<service name="Telerik.Reporting.Service.ReportService"
	behaviorConfiguration="ReportServiceBehavior">
 
	<endpoint address=""
		binding="basicHttpBinding"
		contract="Telerik.Reporting.Service.IReportService">
		<identity>
			<dns value="localhost" />
		</identity>
	</endpoint>
 
	<endpoint address="resources"
		binding="webHttpBinding"
		behaviorConfiguration="web"
		contract="Telerik.Reporting.Service.IResourceService"/>
 
	<endpoint address="mex"
		binding="mexHttpBinding"
		contract="IMetadataExchange" />
</service>

<behavior name="ReportServiceBehavior">
	<serviceMetadata httpGetEnabled="true" />
	<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>

<
connectionStrings> <add name="Postgres" connectionString="provider=PostgreSQL;host=...;user=...;password=...;Unicode=true"  providerName="Devart.Data.Universal" /> </connectionStrings>

I replaced the connection info with ... so I can post it here.

I made a report using the designer (this part worked out of the box for me):

namespace PowerBrowser.Web.Modules.Reporting
{
    public partial class ReportZakenDashboard : Telerik.Reporting.Report
    {
        public ReportZakenDashboard()

Added it to the Silverlight client control:

<report:ReportViewer ReportServiceUri="../ReportService.svc"
    Report="PowerBrowser.Web.Modules.Reporting.ReportZakenDashboard, PowerBrowser.Web" />

The key part here is that you have to specity the full assembly name, but you can thankfully leave out the version.

Regards,

Bayram

0
Peter
Telerik team
answered on 17 Dec 2012, 01:50 PM
Hi Bayram,

How to set up our reporting service is elaborated in the How to: Host WCF Service in IIS help article. 

However if you want to override GetState and SetState, you can derive from ReportServiceBase as elaborated in the How to: Create Self-Hosted Telerik Reporting WCF Service help article.

About the expected rendering, the Silverlight report viewer works with XAML and XAMLInteractive. They are not in the list because they are only meaningful for the Silverlight report viewer.

All the best,
Peter
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Tags
General Discussions
Asked by
B
Top achievements
Rank 2
Answers by
Peter
Telerik team
B
Top achievements
Rank 2
Share this question
or