[英]Printing info using a WCF service
我是Web服务的新手,特别是WCF服务,但我处理得很好。 我的情况如下:我有一个客户端应用程序,该应用程序调用WCF服务,而调用WCF服务则更为明显。 一切都可以正常进行,但是我现在需要打印,这就是我遇到的问题。 我想要的是客户端应用程序,它可以调用WCF服务来打印发票。 我想为他们使用.rdlc报告。 但是我不知道如何将它们传递给客户端应用程序。 正如我所说,我需要传递所有准备打印的信息,因此客户端应用程序无法更改任何内容。 只是打印。
我需要一些帮助或建议以实现此目标。 如果没有其他方法,我可以在客户端应用程序中创建rdlc,但我确实想避免这种情况。
以防万一,我的客户端应用程序是Winform应用程序,我正在使用C#,实体框架4和.NET 4。
您可以让服务将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字节数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.