从WCF返回文件的最佳做法是什么?

时间:2022-01-07 01:06:15

We have a reporting solution that works like this.

我们有一个像这样工作的报告解决方案。

  1. User orders the report to be created and the service method returns it
  2. 用户命令创建报告,服务方法返回它

  3. Report is created (this can take a while) as a file
  4. 创建报告(这可能需要一段时间)作为文件

  5. Client app polls to see if the report is finished
  6. 客户端应用程序轮询以查看报告是否已完成

  7. The client app requests the finished report
  8. 客户端应用程序请求完成的报告

The report can be of the types xml, xls, txt, etc.

报告可以是xml,xls,txt等类型。

What is best practice for sending the report file to the client? I have seen a sample using REst and Stream, but that does not fit so well.

将报告文件发送给客户端的最佳做法是什么?我已经看过使用REst和Stream的示例,但这并不适合。

What datatype must we use if we want to return it in a DTO?

如果我们想在DTO中返回它,我们必须使用什么数据类型?

2 个解决方案

#1


When returning files from WCF, I would recommend checking out Streaming Message Transfer.

从WCF返回文件时,我建议检查流式消息传输。

This allows you to return files as a stream - rather than having to assemble them in full on your server before sending them back. This way, you can stream back even huge files without putting too much burden on your server.

这允许您将文件作为流返回 - 而不是必须在发送它们之前将它们完整地组装在服务器上。这样,您可以回传甚至是大型文件,而不会给您的服务器带来太多负担。

Marc

#2


You could use netTcpBinding or netPeerTcpBinding for WCF Services for transfering files.

您可以将netTcpBinding或netPeerTcpBinding用于WCF服务以传输文件。

Look here for comparison: http://www.pluralsight.com/community/blogs/aaron/archive/2007/03/22/46560.aspx

在这里查看比较:http://www.pluralsight.com/community/blogs/aaron/archive/2007/03/22/46560.aspx

#1


When returning files from WCF, I would recommend checking out Streaming Message Transfer.

从WCF返回文件时,我建议检查流式消息传输。

This allows you to return files as a stream - rather than having to assemble them in full on your server before sending them back. This way, you can stream back even huge files without putting too much burden on your server.

这允许您将文件作为流返回 - 而不是必须在发送它们之前将它们完整地组装在服务器上。这样,您可以回传甚至是大型文件,而不会给您的服务器带来太多负担。

Marc

#2


You could use netTcpBinding or netPeerTcpBinding for WCF Services for transfering files.

您可以将netTcpBinding或netPeerTcpBinding用于WCF服务以传输文件。

Look here for comparison: http://www.pluralsight.com/community/blogs/aaron/archive/2007/03/22/46560.aspx

在这里查看比较:http://www.pluralsight.com/community/blogs/aaron/archive/2007/03/22/46560.aspx