gpt4 book ai didi

servicestack - ServiceStack 是否支持二进制响应?

转载 作者:行者123 更新时间:2023-12-03 15:14:30 30 4
gpt4 key购买 nike

ServiceStack 服务中是否有任何机制来返回流/大型二进制数据? WCF 的 MTOM 支持虽然笨拙,但在返回大量数据而没有文本转换开销方面很有效。

最佳答案

我喜欢服务堆栈,这个小代码足以从内存流中返回一个 Excel 报告

public class ExcelFileResult : IHasOptions, IStreamWriter
{
private readonly Stream _responseStream;
public IDictionary<string, string> Options { get; private set; }

public ExcelFileResult(Stream responseStream)
{
_responseStream = responseStream;

Options = new Dictionary<string, string> {
{"Content-Type", "application/octet-stream"},
{"Content-Disposition", "attachment; filename=\"report.xls\";"}
};
}

public void WriteTo(Stream responseStream)
{
if (_responseStream == null)
return;

_responseStream.WriteTo(responseStream);
responseStream.Flush();
}
}

关于servicestack - ServiceStack 是否支持二进制响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6245616/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com