WCF Stream-改变位置 [英] WCF Stream- changing position
问题描述
我的客户端从另一个客户端获取一个流,但我的客户端只需要从该流的中间读取.
My client gets from another client a stream but my client need to read only from the middle of that stream.
在 WCF 中,我得到的流无法转换为 FileStream
,即使其他客户端在将该流提供给我之前在开始时将该流创建为 FileStream
客户.
In WCF, the stream I get, cannot be converted to FileStream
even if the other client created that stream at the start as FileStream
before he gave that stream to my client.
这就是为什么我的客户不能这样做:
Thats why my client cant do that:
Stream1.Read(Buffer, Middle_Of_Stream, Buffer.Length)
任何解决方案将不胜感激!
*流媒体模式 = 流媒体.
*streaming mode = streaming.
推荐答案
您在客户端上获得的流无法转换为文件流,因为它可能绑定到用于转移.服务器中的 FileStream
不能(并且不应该,出于多种原因,安全性通常是其中之一)被客户端访问,因此 WCF 所做的是从文件流中读取,并复制字节到网络流.在客户端上,您会获得只读(不可搜索)流.
The stream you get on the client cannot be converted to a file stream because it's likely bound to the network stream which was used for the transfer. A FileStream
in the server cannot (and should not, for many reasons, with security being often one of them) accessed by a client, so what WCF does is read from the file stream, and copies the bytes to the network stream. On the client you get a readonly (and non-seekable) stream.
如果您想在客户端将其转换为文件流,您可以创建一个新文件(可能在临时目录中),然后保存您在代理调用时获得的流.
If you want to convert it to a file stream at the client side, you can create a new file (possibly on the temp directory), then save the stream you get at the proxy call to it.
这篇关于WCF Stream-改变位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!