Kis*_*mar 3 .net c# wcf stream
我有一个WCF服务,它使用Stream类上传文档.
在此之后,我想获取文档的大小(流的长度),以更新FileSize的fileAttribute.
但是这样做,WCF引发了一个例外
Document Upload Exception: System.NotSupportedException: Specified method is not supported.
at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.get_Length()
at eDMRMService.DocumentHandling.UploadDocument(UploadDocumentRequest request)
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题.
在此之后,我想获取文档的大小(流的长度),以更新FileSize的fileAttribute.
不,不要那样做.如果您正在编写文件,则只需编写该文件即可.最简单的:
using(var file = File.Create(path)) {
source.CopyTo(file);
}
Run Code Online (Sandbox Code Playgroud)
或者在4.0之前:
using(var file = File.Create(path)) {
byte[] buffer = new byte[8192];
int read;
while((read = source.Read(buffer, 0, buffer.Length)) > 0) {
file.Write(buffer, 0, read);
}
}
Run Code Online (Sandbox Code Playgroud)
(不需要事先知道长度)
请注意,一些WCF选项(完整的消息安全性等)要求在处理之前验证整个消息,因此永远不能真正流式传输,因此:如果大小很大,我建议您改为使用客户端拆分并发送它的API碎片(然后在服务器上重新组装).
| 归档时间: |
|
| 查看次数: |
3764 次 |
| 最近记录: |