简体   繁体   中英

WCF file streaming - timing issue

I've implemented a WCF service in streaming mode to transfer larger files over the Internet.

So far, so good.

For statistics purposes, I want to log how long a transfer takes and which size has been transfered. The size is not the matter, but tracking the transfer time is a bit tricky.

For my need, I've implemented a DownloadStream class which derives from MemoryStream. This class has two events: The first is triggered by start reading and the second by finish reading. It works fine. http://www.danflash.com/files/code/DownloadStream.txt

But if a client (WCF client) calls a WCF method to get the stream, a strange thing happens. On the client side, I get the reference for the stream and can read from it sequentially. It means, I can take the time before reading from the stream and afterwards and get the duration for the transfer.

But if I try to do that on the server side, the whole stream will be read automatically, before any client starts with reading from it. It seems that the stream content will be copied to the memory.

Is there a way to track the transfer time on server side?

The payload is typically buffered in memory before transmission starts, in order to allow for the correct content-length headers to be sent, the entire payload to be validated, the payload encrypted (if message encryption is enabled it is applied before the payload is sent; contrast with transport encryption which can be streamed), to apply transformations such as MTOM (which happens after the payload has been constructed), and to enforce quotas.

You might be able to time this better with a WCF inspector .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM