问题
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