【问题标题】:Passing a FileStream to WCF throws "Timeouts are not supported on this stream" exception将 FileStream 传递给 WCF 会引发“此流不支持超时”异常
【发布时间】:2013-07-02 21:28:03
【问题描述】:

尝试将小型 FileStream 传递给我的 WCF 服务时,我收到“此流不支持超时”错误。谁能看到我做错了什么?

界面:

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

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"/>

【问题讨论】:

    标签: wcf filestream


    【解决方案1】:

    不要使用FileStream 作为参数,而是使用StreamFileStream 是绑定到本地文件系统的流;一旦您开始传输数据,另一端的流将来自网络,因此不能在那里使用 FileStream。

    您可以相信它几乎相同,但 Stream 被 WCF 以特殊方式处理并绕过许多内部任务。

    另外,对于发送大数据,请考虑阅读this great article

    【讨论】:

      【解决方案2】:

      我猜这里的问题是关于 ReadTimeOut 和 WriteTimeOut 属性。在引擎盖下,WCF 必须尝试设置它们,并且由于这些未在 FileStream 类中实现,因此会引发异常。因此,如果您将方法参数类型定义为 Stream WCF 应该创建数据流所需的适当流。我猜是 NetworkStream。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多