您可以让您的服务将 RDLC 转换为 PDF 并将 PDF 作为字节数组发送到您的 WCF 客户端。然后,客户端可以将字节数组保存为临时文件目录中的 .pdf 文件,然后要求操作系统启动注册用于处理 PDF 的默认应用程序(acrobat,...)。
例如,这是我在我的 MVVM 视图模型中为 WPF 客户端下载、保存和启动 PDF 报告的方法。服务器发送一个 ReportDTO,其中 Report 为字节数组,以及 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 字节数组。