views:

394

answers:

1

Hi,

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

+1  A: 

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
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 ONeill
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
Does not appear to be, that's where I think the problem lies. I'll design around it then, thanks Steve,
Ryan ONeill