I have a service that I call from Silverlight. It is both WCF and REST. My Silverlight client calls it fine, however, when it is a WebClient call, an exception in the service does not come back to the client. I only get "Server not found", not the error message. For the WCF call, I use a SilverlightFaultBehavior on the server and that DOES get the error message of the exception back.
But either that SilverlightFaultBehavior is goofing up the REST exception, or I need to do something different.
Here is the REST call and completed event handler (in Oxygene language):
function ViewModel.GetRESTVSDSInfo : VSDS.Data.DataContracts.VSDSInfo; begin IsBusy := true; VSDSInfo := nil; var wc := new WebClient; if UseJson then wc.Headers[HttpRequestHeader.Accept] := "application/json" else wc.Headers[HttpRequestHeader.Accept] := "application/xml"; var uri := new Uri( Application.Current.Host.Source, '../../Service.svc/Rest/VSDSInfo' ); wc.DownloadStringCompleted += wcRestVSDSInfoDownloadStringCompleted; wc.DownloadStringAsync( uri ); end; method ViewModel.wcRestVSDSInfoDownloadStringCompleted(sender: Object; e: DownloadStringCompletedEventArgs); begin IsBusy := false; var wc := WebClient( sender ); wc.DownloadStringCompleted -= wcRestVSDSInfoDownloadStringCompleted; if e.Error <> nil then begin MessageBox.Show( 'Error: ' + e.Error.Message ); exit; end; if UseJson then self.VSDSInfo := SerializationHelper.FromJson<VSDS.Data.DataContracts.VSDSInfo>( e.Result ) else self.VSDSInfo := SerializationHelper.FromXml<VSDS.Data.DataContracts.VSDSInfo>( e.Result ); SurveyHeader.VSDSInfo := self.VSDSInfo; InitData; end;
Here is the WCF call and completion handler:
function ViewModel.GetWCFVSDSInfo : VSDS.Data.DataContracts.VSDSInfo; begin IsBusy := true; VSDSInfo := nil; Proxy := ServiceProxy.NewClient; Proxy.GetVSDSInfoCompleted += ProxyGetWCFVSDSInfoCompleted; Proxy.GetVSDSInfoAsync; end; method ViewModel.ProxyGetWCFVSDSInfoCompleted(sender: Object; e: GetVSDSInfoCompletedEventArgs ); begin IsBusy := False; if sender <> nil then begin Proxy.GetVSDSInfoCompleted -= ProxyGetWCFVSDSInfoCompleted; Proxy.CloseAsync; end; if e.Error <> nil then begin MessageBox.Show( 'Error: ' + e.Error.Message ); exit; end; self.VSDSInfo := e.Result; SurveyHeader.VSDSInfo := self.VSDSInfo; InitData; end;
And here is the service code:
function VSDSService.GetVSDSInfo: VSDSInfo; begin try using db := new Database( 'VSDS' ) do begin result := db.GetVSDSInfo; end; except on e: Exception do begin raise new System.Data.Services.DataserviceException( e.Message ); end; end; end;
I've tried a few different exception types. Just a plain Exception, a WebFaultException, etc. Nothing made a difference.
Here is the relevant web.config section for the SilverlightFaultBehavior:
<extensions><behaviorExtensions><add name="silverlightFaults" type="Silverlight.ServiceFaults.SilverlightFaultBehavior, SilverlightFaultBehavior"/></behaviorExtensions></extensions><behaviors><endpointBehaviors><behavior name="SilverlightFaultBehavior"><silverlightFaults/></behavior><behavior name="VSDSRestfulBehavior"><webHttp helpEnabled="true" automaticFormatSelectionEnabled="true"/><dataContractSerializer maxItemsInObjectGraph="2147483647"/></behavior></endpointBehaviors><serviceBehaviors><behavior name="VSDSBehavior"><serviceDebug includeExceptionDetailInFaults="true"/><serviceMetadata httpGetEnabled="true"/><!--<serviceMetadata httpsGetEnabled="true"/>--><dataContractSerializer maxItemsInObjectGraph="2147483647"/></behavior></serviceBehaviors></behaviors>