views:

34

answers:

2

I'm sending large files over WCF and I'm using transferMode="Streamed" in order to get this working, and it is working fine.

The thing is sometimes those files are just too big, and I want to give the client some sort of feedback about the progress.

Does anybody have a godd solution/idea on how to acomplish this?

EDIT: I don't command the read of the file in either side (client or server) if I did I could just give feedback on the read function of the stream.

EDIT2: part of my code to help others understand my problem

Here's my contract

    [OperationContract]
    FileTransfer Update(FileTransfer request);

and here's the definition of FileTransfer

[System.ServiceModel.MessageContractAttribute(WrapperName = "FileTransfer", WrapperNamespace = "http://tempuri.org/", IsWrapped = true)]
public class FileTransfer : IDisposable
{
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "dummy", Order = 0)]
    public Stream FileByteStream;

    public void Dispose()
    {
        if (FileByteStream != null)
        {
            FileByteStream.Close();
            FileByteStream = null;
        }
    }

}

so, in my service (hosted on IIS) I just have something like this:

request.FileByteStream;

and WCF itself reads the stream, right?

I hope this helps people out to understand my problem... please let me know if you need further info

A: 

What about adding total stream size as custom Soap header (use MessageContracts). Then you can process the stream on client in chunks (like reading to buffer of defined size in loop) and for each chunk you can notify client about processed increment in context of expected size.

Ladislav Mrnka
I like how that sounds, but, I don't get to do any stream manipulation... WCF takes care of that and my service starts processing (I guess) after the whole file is on the server
sebastian
In that case my solution will not work. It is usable for downloading stream not for uploading.
Ladislav Mrnka
A: 

The only way I see right now is by creating another operation that report the number of bytes read by the streamed operation. This would require activating sessions and multi-threading at the server side and implementing a asynchronous call from the client together with calls to the "progress reporting" operation.

The client knows the size of the stream (assuming the client is the sender), it can extract a progress percentage from the known total size and the reported size from the server.

EDIT: My comment works under the assumption that the client is uploading data. So the server knows of much data it has already read from the stream while the client knows the size of the data. If the server exposes an operation that reports the volume of data it has read so far, the client will be able to calculate the progress percentage by calling this operation.

Johann Blais
as from @Ladislav answer. I don't see how the server can tell the progress... that's the whole point of my question, it might not be as clear as a thought :(
sebastian
Should I add a new behavior in the middle or something?
sebastian
The server does not tell the progress, it reports how much it has read from the client so far through another operation. I have edited my answer accordingly.
Johann Blais