FeveZ,
You can easily stream your report as a PDF straight to the browser, too.
Looks much
more professional than the ugly crystal control on the screen. Here's how to
do what you want (in a nutshell):
1) In your webservice, set your report to get its data from a dataset
2) Have your data layer retrieve the report data in the form of a DataSet
3) Set the reports DataSource (.SetDataSource) to the DataSet in 3)
4) Export the report to a stream (ExportToStream), and convert it to a array
of bytes
5) Return the byte array to the calling web page, which can
Response.BinaryWrite it to the client browser
6) Wipe hands on pants and repeat!
Here's sample code:
yada yada yada: it's always nice to see the USINGS!!
using System;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using Microsoft.ApplicationBlocks.ExceptionManagement;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
[WebMethod]
public byte[] GetDataForDTReport(int fiscalYearId,int programId,int
languageId)
{
// Declaration section
ReportDs report = new ReportDs(); //our data service
DataSet reportData = new DataSet();
System.IO.Stream dataStream;
byte[] pdfReport = new byte[1];
ExportRequestContext requestCtx = new ExportRequestContext();
// Create an instance of your report class
DTReport repDoc = new DTReport();
bool dataReturned = true;
try
{
// Validation section
// Call the data services for the report
reportData =
report.GetDataForDTReport(fiscalYearId,programId,l anguageId);
//If tables are returned
if(reportData.Tables.Count > 0)
{
//If at least one table has no rows
foreach(DataTable table in reportData.Tables)
{
if(table.Rows.Count == 0)
{
dataReturned = false;
break;
}
}
if(dataReturned)
{
// Set the data source for the report
repDoc.SetDataSource(reportData);
repDoc.ExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat;
repDoc.ExportOptions.FormatOptions = new PdfRtfWordFormatOptions();
requestCtx.ExportInfo = repDoc.ExportOptions;
dataStream = repDoc.FormatEngine.ExportToStream(requestCtx);
// Convert the data stream with the pdf report into an array
pdfReport = new byte[dataStream.Length];
dataStream.Read(pdfReport,0,(int)dataStream.Length );
dataStream.Close();
}
}
return pdfReport;
}
catch(Exception ex)
{
// Wrap exception and rethrow
throw new BaseApplicationException("Web Service Exception", ex);
}
finally
{
// Cleanup code
reportData = null;
dataStream = null;
pdfReport = null;
}
}
--
Tim Gallivan
I know I'm a great teacher because when I give a lesson, the person never
comes back.
"FeveZ" <Fe***@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
I've been stuck on a problem now for ages and i'm about ready to pack my
project in because of it lol.
OK here is my scenario.
I have an existing Crystal Report, which I have added to my solution and
published it as a webservice. This report takes it data from an SQL server
on another machine.
The user will have a windows form in a little app i'm writing where it has
a web reference to this report... it will show the report from this Web
Service in the crystal report view control.
I set the report datasource to this web service... however I keep getting
the database logon screen whenever I run the report... if I enter the
correct password it runs fine... but my problem is I dont want this sodding box to
come up all the time!
Ive seen examples of other users problems where they are to set the logon
details for every table but I cannot seem to do this myself as I cant get
to the actual crystal report object from the web service to change the
database table logon bits.
Am I making sense here? Someone please help ths is really sapping my will
to live...
Thanks in advance.
FeveZ