我已经使用WCF的流实现了文件上传。一切都按预期进行,但是我遇到了一个问题:我分配 4kb 缓冲区来从传入流中读取数据,但 WCF 仅读取 255 字节。这是我的上传功能:
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)。有什么我可以更改的设置,还是我做错了什么?
如果可以的话请发布您的配置。配置应指定默认值或覆盖值,如下所示:
<binding name="FileTransferServicesBinding"
maxReceivedMessageSize="1048576" messageEncoding="Mtom">
<readerQuotas maxArrayLength="1048576" maxBytesPerRead="1048576"
maxNameTableCharCount="1048576" maxStringContentLength="1048576"> </readerQuotas>
</binding>
尝试这个MSDN 链接 http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/7b9e9cd9-49f1-498c-85c5-fc869dddae87那家伙提到他也遇到了同样的问题,只获得了 255 字节,他标记了答案,似乎解决了他的问题。它指出:
“为了将流传递给 WCF 方法,Stream 参数必须是操作(或消息正文)中的唯一参数......”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)