Passing a FileStream to WCF throws “Timeouts are not supported on this stream” exception

我是研究僧i 提交于 2019-12-10 14:51:47

问题


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?

Interface:

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

回答1:


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.

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.




回答2:


I guess the issue over here is about the ReadTimeOut and WriteTimeOut properties. Under the hood WCF must be trying to set them up and as these are not implemented in FileStream class it throws the exception. So if you define the method Argument type as Stream WCF should create the appropriate stream that is required for data streaming. I would guess NetworkStream.



来源:https://stackoverflow.com/questions/17436132/passing-a-filestream-to-wcf-throws-timeouts-are-not-supported-on-this-stream-e

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!