Adrian Hara

Working through the .NET maze

  Home  |   Contact  |   Syndication    |   Login
  42 Posts | 0 Stories | 83 Comments | 10 Trackbacks

News

Archives

Post Categories

This has probably been covered in some tutorial videos or "silverlight 3 what's new"s, but due to the fact that I spent the better half of an hour googling about ways to do it, I guess also posting it here for reference won't hurt.

Problem: when calling a WCF service from Silverlight 2, if the service throws an exception, in Silverlight you get a CommunicationException with some mumbo-jumbo in it, not the actual exception or Fault declared on the service.

Fix: in Silverlight 3 there is built-in support on the client-side for FaultException and FaultException<T>. All you need to do it tweak the WCF service a bit so it returns a 200 response code, instead of the default 500 response code, so you actually get the FaultException, as explained here: http://msdn.microsoft.com/en-us/library/dd470096(VS.96).aspx

Also, some more info on this and other new stuff in SL3: http://blogs.msdn.com/silverlightws/archive/2009/03/20/what-s-new-with-web-services-in-silverlight-3-beta.aspx
posted on Wednesday, April 29, 2009 12:25 PM

Feedback

# re: Handling WCF exceptions in Silverlight 3 7/21/2009 11:38 AM Mark
Hi Adrian,
After spending the best part of half a day trying to get this to work I have had no joy.
The link is a little vague on the step by step instruction on what is required. i.e. create this library, add a ref to this project etc. Have you seen any other articles on this that go into more detail. Cheers


# re: Handling WCF exceptions in Silverlight 3 7/21/2009 12:32 PM Adrian Hara
Umm..not really, but the explanations worked for me. What's your exact problem?

# re: Handling WCF exceptions in Silverlight 3 7/22/2009 1:32 AM Mark
The <silverlightFaults/> element is not recognized even after the behaviorExtension has been added to the config.
Did you compile the SilverlightFaultBehavior as a separate dll or just add it as a class to your Service Project?


# re: Handling WCF exceptions in Silverlight 3 7/23/2009 5:58 AM dave
Hi Adrian,
I have a similar query to Mark...

When I try to update my service, I get the error:
The type '....silverLightFaultBehavior....' registered for extension 'silverlightFaults' could not be loaded.

I have the silverlightFaultBehavior code file in the same project and namespace as the web app hosting the service.

Any idea what I'm doing wrong?

# re: Handling WCF exceptions in Silverlight 3 7/23/2009 6:29 AM Adrian Hara
I'm out of the country currently, but next week latest I will take a look at the actual project and get back to you. Hope it's not too late...

# re: Handling WCF exceptions in Silverlight 3 7/27/2009 1:27 AM Adrian Hara
Ok, I looked:
1. I have it in a separate .dll, not in the hosting (web) project.
2. In visual studio, where the behavior extension is used (in the example below this is the "<silverlightFaults/>" element) it gets underlined with a blue squiggly line and the tooltip says it can't be found, however at runtime it works like a charm.

Here's my web.config relevant part from the hosting application:

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SDS.WCF.ServiceImplementation.DataService_Behavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="SDS.WCF.ServiceImplementation.DataService_Behavior" name="SDS.WCF.ServiceImplementation.DataService">
<endpoint behaviorConfiguration="SilverlightFaultBehavior" address="" binding="basicHttpBinding" name="DefaultEndpoint" bindingNamespace="urn:Ssmt.SilverlightDataService.ServiceContracts:v1" contract="SDS.WCF.ServiceContracts.IDataServiceContract"/>
</service>
</services>
<extensions>
<behaviorExtensions>
<add name="silverlightFaults" type="SDS.WCF.ServiceImplementation.WCFHelpers.SilverlightFaultBehavior, SDS.WCF.ServiceImplementation.ServiceImplementation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>

# re: Handling WCF exceptions in Silverlight 3 7/29/2009 12:52 PM Dan
Same problem here with the same error and same blue squiggly line. I have everything in the web project. Anyone able to get this to work?

# re: Handling WCF exceptions in Silverlight 3 7/29/2009 1:53 PM Dan
Nevermind, I got it to work. I put the SilverlightFaultBehavior in a separate assembly, referenced it in the website project, and also before rebuilding and trying out the service, I removed the existing SilverlightFaultBehavior.dll from the website's bin directory.

# re: Handling WCF exceptions in Silverlight 3 9/23/2009 10:34 PM Priya
Followed the instructions but in the client still the FaultException<> block was NOT hit. Instead, the Exception block was. Created the silverlightFaultBehavior.dll and modified the web.config . The debugger does go to SilverlightFaultBehavior . What am I missing?

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: