At least in beta 1, Fault Exception is not supported in Silverlight. I don't think beta2 changed that but I could be wrong.
Here is the way I do it:
I created a custom exception in my WCF side. I have one generic WCF function for my all WCF calls. The return type is called ResponseData I defined this way:
[DataContract]
public class ResponseData
{
[DataMember]
public string StringResult { get; set; }
[DataMember]
public int IntResult { get; set; }
[DataMember]
public double NumericResult { get; set; }
[DataMember]
public bool BooleanResult { get; set; }
[DataMember]
public CustomException Error { get; set; }
[DataMember]
public DataSetData DataSetResult { get; set; }
[DataMember]
public Dictionary<string, string> DictionaryResult { get; set; }
}
[DataContract]
public class CustomException
{
[DataMember(Order = 0)]
public string Message { get; set; }
[DataMember(Order = 1)]
public CustomException InnerException;
public Exception ToException()
{
Exception e;
CustomException ce = this;
if (ce.InnerException != null)
{
Exception inner = ce.InnerException.ToException();
e = new Exception(ce.Message, inner);
}
else
e = new Exception(ce.Message);
return e;
}
}
So if my WCF function I catch any exception and pass that exception to MyResponseData.Error;
[OperationContract]
public ResponseData ProcessRequest(RequestData request)
{
return Process(request);
}
private ResponseData Process(RequestData request)
{
ResponseData result = new ResponseData();
try
{
...
result.StringResult = "Something"; //
}
catch (Exception ex)
{
while (ex.InnerException != null)
ex = ex.InnerException;
result.Error = new CustomException();
result.Error.Message = ex.Message + ex.StackTrace;
}
return result; // this result could contains Error or could contain real data.
}
On Silverlight side in MyWebServiveCompleted call I check both e.Error and e.Result.Error
Hope this would help if somebody want to do this way. Use this CustomExeption I can also send my Exception in the Silverlight side back to Server to do Exception logging.
sladapter
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question