resuming file upload seeking a stream

懵懂的女人 提交于 2019-12-13 20:33:44

问题


I am uploading files from clients to server... when the server program receives the stream, property Length is not supported and CanSeek comes false, how would seeking be possible?? I can get the length if I read it in the client and send as a message header in the message contract but don't know how to seek. Ideas??


回答1:


WCF is not technology for file transfers. Moreover seek is not supported by StreamFormatter used internally because the whole idea of seek in distributed application is nonsense. To make this work correctly internal stream will have to be network protocol with control flow over transferred data which is not. Internally the stream is only array of bytes. It means that even if WCF supported seeking you would still need to transfer all data before seek position.

If you need resume functionality you must implement it by yourselves by manually creating chunks of data and uploading them and appending them to file on the server. Server will control last correctly received chunk and refuse chunks already passed. MSDN has sample implementation using this as custom channel.




回答2:


The stream sample here http://go.microsoft.com/fwlink/?LinkId=150780 does what your trying to do.

WCF\Basic\Contract\Service\Stream\CS\Stream.sln

the sample is explained here

http://msdn.microsoft.com/en-us/library/ms751463.aspx



来源:https://stackoverflow.com/questions/6460759/resuming-file-upload-seeking-a-stream

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