使用WCF流上传文件,从流中读取少量内容 [英] Uploading file with WCF streaming, tiny reads from stream
问题描述
我已经使用WCF的流媒体实现了文件上传。一切都按预期工作,但是我遇到了一个问题:我正在分配4kb的缓冲区以从传入流中读取数据,但是WCF仅读取255个字节。这是我的上传函数:
I've implemented file uploading using WCF's streaming. Everything works as expected, however i faced one issue: i'm allocating 4kb buffer to read from incoming stream, but WCF reads only 255 bytes. Here is my upload function:
public UploadResponse UploadFile(FileDto fileDto)
{
using (var inStream = fileDto.FileStream)
using (var outStream = new FileStream("OutFile.txt", FileMode.Create))
{
var buffer = new byte[4096];
int count;
while ((count = inStream.Read(buffer, 0, buffer.Length)) > 0)
{
outStream.Write(buffer, 0, count);
}
}
return new UploadResponse {DocumentId = -1};
}
此行仅读取255个字节:while(((count = inStream.Read (buffer,0,buffer.Length))> 0)。我可以更改任何设置吗,或者我做错了什么?
Only 255 bytes reading at this line: while ((count = inStream.Read(buffer, 0, buffer.Length)) > 0). Is there any setting i can change, or am i doing something wrong?
推荐答案
我认为您遇到的问题与我相同。我在这里解决了它:通过WCF下载文件的速度比通过IIS慢。
I think you had the same problem I did. I solved it here: File download through WCF slower than through IIS
这篇关于使用WCF流上传文件,从流中读取少量内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!