Silverlight 3.0 has much better support for soap faults than Silverlight 2. But it’s still not perfect.
The majority of the time it works well with WCF services with some tweaks, as this MSDN article explains.
But what about old .ASMX .NET webservices?
There’s a couple things to understand before we handle those soap faults.
First, by limitations on the browser stack that I won’t go into detail, Silverlight can’t handle HTTP 500 responses. So our first task is to make sure that any ASMX responses are HTTP 200.
Second, ASMX faults are not as nice as WCF faults. So we have to handle them a little bit differently once we get them in Silverlight.
Let’s get started on the first task.
The easiest way of making sure all .ASMX responses are sent out of your server as HTTP 200 is to create a IHttpHandler.
To create your IHttpHandler, simply create a standard .NET Class Library, reference System.Web and add a regular class with this code in it:
After creating your IHttpHandler, register it on your .ASMX website web.config
This will basically make every single request to asmx webservices return HTTP 200, no matter what.
By now, if you run your Silverlight client you’ll probably stop getting the super annoying "The remote server returned an error: NotFound." response.
Good. Now all we have to do is get the proper fault details on your asynchronous Silverlight request. Simple:
If you want things really tidy (I didn’t had time for this, sorry), try to write your own error descriptor and use FaultException<T>.
Happy Silverlight coding!
Good reading:
Creating and Handling Faults in Silverlight http://msdn.microsoft.com/en-us/library/dd470096(VS.96).aspx
Data Performance and Fault Strategies in Silverlight 3 http://msdn.microsoft.com/en-us/magazine/ee294456.aspx