使用WCF流上传文件,从流中读取少量内容 [英] Uploading file with WCF streaming, tiny reads from stream

查看:109
本文介绍了使用WCF流上传文件,从流中读取少量内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆