Silverlight 2 Web Services

I am developing a silverlight application that consumes a web service. Calls to this web service are made asynchronously. But when an exception is thrown during an asynchronous call procedure, I get an error on the completed event, but I lost the original information about the exceptions. Regardless of the original exception, I always get the "Remote server returned error: NotFound" back, with a stack that points to "outside" code.

Any advice?

+2


source to share


3 answers


When the service throws an exception, it translates to a 40 (x) HTTP response, which is processed by the browser before the Silverlight plugin can process it. To avoid this, wrap your WCF calls in a try / catch block and send the exception data back to the client with an HTTP response that Silverlight can handle, like 200. Here's an awesome implementation of this strategy for codeproject: http://www.codeproject.com/ KB / silverlight / SilverlightExceptions.aspx



+1


source


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



http://www.fiddler2.com

0


source


  • Follow James Cudd's advice above. Getting more informative error messages will certainly help, and unfortunately you cannot rely on the debugger to generate them for you.

  • Even if you are not a big fan of unit testing, this is the place where it is more than useful. Building a suite of tests that purposefully send your bad data to the webservice and make sure you get informative errors will help you figure out why it doesn't work with your Silverlight application. Writing tests like this takes a different approach, but it will give you more confidence in your code if you know you've tried to damage the web service in every possible way, and it always gives you back something you can use to track down the problem.

0


source







All Articles