0

I have a WCF service which works 100% in the synchronous (blocking) mode and I now need to rework a call so that it uses the async pattern.

The service uses authentication and performs a chunked file transfer from client to server so I have reworked it to use the 'Begin' async prefix to kick off the call.

Now I'm testing for errors by deliberately mangling the user credentials which causes the call to timeout on each part of the file chunk it tries to transfer, which takes ages. The problem is that I don't get any error feedback and can't see how to get any if the async call fails. This leads to some very large files failing to upload at all, but the client being unaware of it as no exceptions are thrown.

I have the Debug->Exceptions->All CLR exceptions ticked to see if there are any exceptions being swallowed but still nothing.

So in summary, how do you get error feedback from async calls in WCF?

Thanks in advance,

Ryan

Ryan O'Neill
  • 5,410
  • 4
  • 46
  • 69
  • Update: Just to clarify, this is a LARGE file that is being chunked, it fails on each chunk (32k) but does not do a callback so I only get to see that the file has failed after it has processed (and failed) every chunk. Which is some time on a 1gb file. – Ryan O'Neill Jan 15 '09 at 21:30

1 Answers1

1

The server caches the exception for you and if you call the end operation completion method for your async call it will throw any exceptions that occured.

private void go_Click(object sender, EventArgs e)
{
    client.BeginDoMyStuff(myValue, new AsyncCallback(OnEndDoMyStuff), null);
}

public void OnEndDoMyStuff(IAsyncResult asyncResult)
{
    this.Invoke(new MethodInvoker(delegate() { 
        // This will throw if we have had an error
        client.EndDoMyStuff(asyncResult);
    }));
}
Steven Robbins
  • 26,441
  • 7
  • 76
  • 90
  • Thanks, I can see how that can be helpful normally but with a large file transfer it will try to transfer the whole file first and timeout on each and every chunk (taking longer than a normal file transfer would). I would have hoped it would have given me the option of failing immediately. – Ryan O'Neill Jan 15 '09 at 21:32
  • Ah, I'm not sure how you are chunking it up (I've never transferred files with WCF), but is there no way you can throw if a single chunk fails? – Steven Robbins Jan 15 '09 at 21:47
  • Does not appear to be, that's where I think the problem lies. I'll design around it then, thanks Steve, – Ryan O'Neill Jan 15 '09 at 22:10