Now after that I want to get the document size (stream length) in order to update the Attribute file for FileSize.
No, do not do this. If you are writing a file, just write the file. With the simplest:
using(var file = File.Create(path)) { source.CopyTo(file); }
or up to 4.0:
using(var file = File.Create(path)) { byte[] buffer = new byte[8192]; int read; while((read = source.Read(buffer, 0, buffer.Length)) > 0) { file.Write(buffer, 0, read); } }
(which does not have to know the length in advance)
Please note that some WCF parameters (full message protection, etc.) require that the entire message be checked before processing, therefore it can never really transmit a stream, therefore: if the size is huge, I suggest you use the API instead where the client breaks it and sends it in parts (which you then collect on the server).
source share