Using Delegates To Follow Upload Progress Via WCF Method

Discussion in 'ASP .Net Web Services' started by pbd22, Nov 4, 2009.

  1. pbd22

    pbd22 Guest

    Hi.

    I have successfully designed a large file upload method using WCF.
    Now, I would like to report progress for each unique file being
    loaded. In my upload method, i have the following code block:

    Code:

    while ((bytesRead = request.FileByteStream.Read(buffer, 0,
    bufferSize)) > 0)
    {
    outfile.Write(buffer, 0, bytesRead);
    totalBytesRead += bytesRead;

    if (this.ProgressChanged != null)
    this.ProgressChanged(this, new ProgressArgs(totalBytesRead,
    request.FileByteStream.Length));

    }



    Which uses the delegate ProgressEventHandler as declared below:

    Code:

    public delegate void ProgressEventHandler(object sender, ProgressArgs
    e);
    public event ProgressEventHandler ProgressChanged;

    I do not use delegates all that much and got this far by following
    examples online. The class ProgressArgs was missing from the example
    but I am guessing that is where the calculation takes place and is
    returned? Something like:

    return Convert.ToInt32((totalBytesRead * 100) / fileSize) ?

    So, my questions are thus:

    1) Assming I have declared and called my ProgressChanged event
    correctly, what is the role of ProgressArgs?

    2) How do I report progress back to the client? My WCF method call
    currently has a 'void' return type:

    Code:

    upload.UploadFile(fileinfo, m_objFile.InputStream);

    Will I need to fire a simultaneous JavaScript method that calls a WCF
    JSON method or something of that nature? If so, it is still unclear to
    me how the delegate is used/accessed to report **which file** and
    **what precent of it** is being uploaded.

    Thanks!

    PS - I am using ASP.NET 2.0 / Framework 3.5 / C# / and I am self-
    hosting currently.
    pbd22, Nov 4, 2009
    #1
    1. Advertising

  2. pbd22

    pbd22 Guest

    On Nov 4, 12:06 pm, pbd22 <> wrote:
    > Hi.
    >
    > I have successfully designed a large file upload method using WCF.
    > Now, I would like to report progress for each unique file being
    > loaded. In my upload method, i have the following code block:
    >
    > Code:
    >
    > while ((bytesRead = request.FileByteStream.Read(buffer, 0,
    > bufferSize)) > 0)
    > {
    >     outfile.Write(buffer, 0, bytesRead);
    >     totalBytesRead += bytesRead;
    >
    >     if (this.ProgressChanged != null)
    >         this.ProgressChanged(this, new ProgressArgs(totalBytesRead,
    > request.FileByteStream.Length));
    >
    > }
    >
    > Which uses the delegate ProgressEventHandler as declared below:
    >
    > Code:
    >
    > public delegate void ProgressEventHandler(object sender, ProgressArgs
    > e);
    > public event ProgressEventHandler ProgressChanged;
    >
    > I do not use delegates all that much and got this far by following
    > examples online. The class ProgressArgs was missing from the example
    > but I am guessing that is where the calculation takes place and is
    > returned? Something like:
    >
    > return Convert.ToInt32((totalBytesRead * 100) / fileSize) ?
    >
    > So, my questions are thus:
    >
    > 1) Assming I have declared and called my ProgressChanged event
    > correctly, what is the role of ProgressArgs?
    >
    > 2) How do I report progress back to the client? My WCF method call
    > currently has a 'void' return type:
    >
    > Code:
    >
    > upload.UploadFile(fileinfo, m_objFile.InputStream);
    >
    > Will I need to fire a simultaneous JavaScript method that calls a WCF
    > JSON method or something of that nature? If so, it is still unclear to
    > me how the delegate is used/accessed to report **which file** and
    > **what precent of it** is being uploaded.
    >
    > Thanks!
    >
    > PS - I am using ASP.NET 2.0 / Framework 3.5 / C# / and I am self-
    > hosting currently.


    Anything else I can add to clarify?
    pbd22, Nov 5, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Birtle
    Replies:
    3
    Views:
    2,417
  2. Charlie Zhang
    Replies:
    3
    Views:
    1,244
    Paul Lutus
    Aug 16, 2004
  3. Simon
    Replies:
    0
    Views:
    996
    Simon
    Oct 13, 2009
  4. Cindy Lee
    Replies:
    1
    Views:
    2,079
    Mr. Arnold
    Mar 19, 2010
  5. News123
    Replies:
    9
    Views:
    525
    News123
    May 14, 2010
Loading...

Share This Page