1

My client gets from another client a stream but my client need to read only from the middle of that stream.

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)

Any solutions will be appreciated!

*streaming mode = streaming.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171

1 Answers1

1

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.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • Reading all the stream and wtire it to a filestream and then read the parts I need, agian, is not a good solution. I must find a way to read **only** couple of bytes in the start/middle/end only. What other options do you have? – Stav Alfi Jul 12 '12 at 11:54
  • 1
    If you only want to read some bytes, then change your operation to return a stream not from the whole file, but from the portion of the file which you're interested at. Your operation would need to take the offset and count parameters in addition to whatever it takes now. – carlosfigueira Jul 12 '12 at 23:16