views:

98

answers:

3

Hi,

I'm developing a silverlight application that consumes a webservice. Calls to this webservice are made Asynchronously. But when an exception occurs during a procedure of the async call, I get an error on the completed event but i lost my original exceptions information. Independent of what the original exception was, I always get "The remote server returned an error: NotFound" back, with stack that points to "external" code.

Any advice?

A: 

This happens with any exception in your SL to WCF, sometimes you can find the innerexception with Fiddler2 in the transfered data or you might see the HTTP error code which can give you a hint , other times it's harder to find. This is my big request item for SL 4.0, better WCF debugging.

http://www.fiddler2.com

Paully
Hi Paully, Thank you for the response.Yes I eventually figured that out, but how can I catch the original exception on the SL side?
You can try catch in the reference.vb code but it get's removed every time you update and doesn't really solve the problem because you don't have the original exception. I never do this unless I'm doing some kind of demo where I need to hide error messages.
Paully
If I'm understanding you correctly, if your SL app consumes a webservice it's impossible to catch the original exception that happens on the service side? Is there a work around for this?
+1  A: 

When the service throws an exception it's translated to a 40(x) HTTP response that gets handled by the browser before the Silverlight plugin can handle it. To avoid this, wrap your WCF calls in a try/catch block and send exception data back to the client through an HTTP response that can be handled by Silverlight, such as 200. Here's a terrific implementation of this strategy on codeproject: http://www.codeproject.com/KB/silverlight/SilverlightExceptions.aspx

James Cadd
Another helpful link :http://msmvps.com/blogs/theproblemsolver/archive/2009/01/27/returning-exception-information-to-a-silverlight-client-through-wcf.aspx
A: 
  1. Follow James Cadd's advice above. Getting more informative error messages will certainly help and, unfortunately, you can't rely on the debugger to generate them for you.

  2. Even if you're not a big fan of unit testing, this is a place where it's more than worthwhile. Constructing a set of tests that will purposefully send your webservice bad data and making sure that you get back informative errors will help set you up to figure out why it's not working with the Silverlight app. Writing these kinds of tests takes a different way of thinking, but it will give you a lot of confidence in your code if you know that you've tried to break the webservice in every possible way and it always gives you back something you can use to trace the problem.

Raumornie