使用WCF服务打印信息
本文关键字:信息 打印 服务 WCF 使用 | 更新日期: 2023-09-27 18:02:57
我是webservices的新手,特别是WCF服务,但我处理得很好。我的情况如下:我有一个客户端应用程序调用WCF服务,显然,WCF服务。一切正常,但我现在需要打印,这就是我卡住的地方。我想要的是客户端应用程序调用WCF服务来打印发票。我想使用.rdlc报告。但我不知道如何将它们传递给客户端应用程序。正如我所说,我需要的是传递所有准备打印的信息,因此客户端应用程序不能改变任何东西。只是打印。
我需要一些帮助或建议如何实现这一点。如果没有其他方法,我可能会在客户端应用程序中创建rdlc,但我真的想避免这种情况。
为了以防万一,我的客户端应用程序是一个Winform应用程序,我使用c#,实体框架4和。net 4。
您可以让您的服务将RDLC转换为PDF,并将PDF作为字节数组发送给您的WCF客户端。然后,客户端可以将字节数组保存为临时文件目录中的。pdf文件,然后要求操作系统启动默认应用程序,注册为处理pdf (acrobat,…)。
作为一个例子,下面是我在我的MVVM视图模型中使用的方法,用于WPF客户端下载、保存和启动PDF报告。服务器发送一个ReportDTO,其中报告是一个字节数组,以及FileName(扩展名为".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.
}
这允许您将所有报表定义保留在服务器上,并将WCF接口简化为提供PDF字节数组。