I´m new to webservices, specially WCF´services but I´m handling it ok. My situation is the following one: I have a client app that calls the WCF services and obviusly, the WCF services. All is working as it should, but I need to print now, and thats where I´m stucked. What I want, is the client app to call a WCF service to print an invoice. I thought of using .rdlc reports for them. But I don´t have any idea of how can I passed them to the client app. As I say, what I need, is the pass all the info ready to print, so the client app cant change anything. Just print.
I need some help or advice of how to achieve this. If there is no other way, I may create the rdlc in the client app, but I really want to avoid this.
Just in case, my client app is a Winform app, and I´m using C#, Entity framework 4 and .NET 4.
You could have your service convert the RDLC into a PDF and send the PDF as a byte array to yor WCF client. The client can then save the byte array as a .pdf file in the temporary file directory, and then ask the OS to launch the default application that registered for handling PDFs (acrobat,...).
As an example, here is the method I use in my MVVM viewmodel for a WPF client to download, save and launch a PDF report. The server sends a ReportDTO with the Report as a byte array, and FileName (report name with extension ".pdf"):
[DataContract(Name="ReportDTO", Namespace="http://chasmx/2013/2")]
public sealed class ReportDTO
{
/// <summary>
/// Filename to save the report attached in <see cref="@Report"/> under.
/// </summary>
[DataMember]
public String FileName { get; set; }
/// <summary>
/// Report as a byte array.
/// </summary>
[DataMember]
public byte[] @Report { get; set; }
/// <summary>
/// Mimetype of the report attached in <see cref="@Report"/>. This can be used to launch the application registered for this mime type to view the saved report.
/// </summary>
[DataMember]
public String MimeType { get; set; }
}
public void ViewReport()
{
ServiceContracts.DataContract.ReportDTO report;
String filename;
this.Cursor = Cursors.Wait;
try
{
// Download the report.
report = _reportService.GetReport(this.SelectedReport.ID);
// Save the report in the temporary directory
filename = Path.Combine(Path.GetTempPath(), report.FileName);
try
{
File.WriteAllBytes(filename, report.Report);
}
catch (Exception e)
{
string detailMessage = "There was a problem saving the report as '" + filename + "': " + e.Message;
_userInteractionService.AskUser(String.Format("Saving report to local disk failed."), detailMessage, MessageBoxButtons.OK, MessageBoxImage.Error);
return;
}
}
finally
{
this.Cursor = null;
}
System.Diagnostics.Process.Start(filename); // The OS will figure out which app to open the file with.
}
That lets you keep all report definitions on the server and dumbs the WCF interface to your client down to supplying a PDF byte array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.