将FileStream传递给WCF会引发“此流不支持超时".例外 [英] Passing a FileStream to WCF throws "Timeouts are not supported on this stream" exception

查看:835
本文介绍了将FileStream传递给WCF会引发“此流不支持超时".例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试将小的FileStream传递给WCF服务时,出现此流不支持超时"错误.有人可以看到我在做什么错吗?

When trying to pass a small FileStream to my WCF service I get "Timeouts are not supported on this stream" error. Can anyone see what I'm doing wrong?

接口:

[OperationContract]
List<SystemClass> ReadExcelFile(System.IO.FileStream stream);

Web.Config

Web.Config

<bindings>
  <basicHttpBinding>
    <binding name="streaming" maxReceivedMessageSize="2147483647" transferMode="Streamed">
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="MISDashboard.wcfService" behaviorConfiguration="">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="streaming" contract="MISDashboard.wcfService"></endpoint>
  </service>
</services>
...
<httpRuntime maxRequestLength="2147483647"/>

推荐答案

请勿使用FileStream作为参数,而是使用Stream. FileStream是绑定到本地文件系统的流;一旦开始传输数据,另一端的数据流将来自网络,因此无法在其中使用FileStream.

Do not use FileStream as parameter but Stream. A FileStream is a stream bound to the local file system; once you start transferring the data, in the other side the stream will be coming from the network, so a FileStream can't be used there.

您可以相信它是一样的,但是Stream被WCF以特殊方式对待,并绕过了许多内部任务.

You could believe it's pretty the same but Stream is treated in a special way by WCF and by-pass many internal tasks.

另外,要发送大数据,请考虑阅读这篇很棒的文章.

Also, for sending Large Data consider reading this great article.

这篇关于将FileStream传递给WCF会引发“此流不支持超时".例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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