Answered by:
WCF FaultException

Question
-
Can someone please help me out with the following link via StackOverFlow?
You need to copy the entire link and paste in your browser instead of clicking on it, because it doesn't pick up after the hyphen.
http://stackoverflow.com/questions/22072455/wcf-faultexception
Bill Yeager
- Moved by Fred Bao Friday, February 28, 2014 1:54 AM It is a thread about WCF
Thursday, February 27, 2014 7:14 PM
Answers
-
Hi Bill,
Please try define the CustomFault(MathFault in this example) as a data contract rather than Operation Contract, like:
[DataContract] public class MathFault { //... }
At the client side:
static void Main(string[] args) { ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); try { int value1 = 22; int value2 = 0; int result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); client.Close(); } catch (FaultException<MathFault> e) { Console.WriteLine("FaultException<MathFault>: Math fault while doing " + e.Detail.Operation + ". Problem: " + e.Detail.ProblemType); client.Abort(); Console.ReadLine(); } }
See more: http://msdn.microsoft.com/en-us/library/ms752208(v=vs.110).aspx
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Haixia_Xie Friday, February 28, 2014 6:51 AM
- Marked as answer by Bill_Yeager Friday, February 28, 2014 5:16 PM
Friday, February 28, 2014 6:50 AM
All replies
-
Hello,
This forum is used to st feedback, questions and suggestions related to Released (RTM) versions of WCF Data Services Framework (formerly known as ADO.NET Data Services and Project "Astoria").post feedback, questions and suggestions related to Released (RTM) versions of WCF Data Services Framework (formerly known as ADO.NET Data Services and Project "Astoria").
Since this issue is more regarding WCF, I will move it to the suitable forum. There are WCF experts who will help you better.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Friday, February 28, 2014 1:51 AM -
Hi Bill,
Please try define the CustomFault(MathFault in this example) as a data contract rather than Operation Contract, like:
[DataContract] public class MathFault { //... }
At the client side:
static void Main(string[] args) { ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); try { int value1 = 22; int value2 = 0; int result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); client.Close(); } catch (FaultException<MathFault> e) { Console.WriteLine("FaultException<MathFault>: Math fault while doing " + e.Detail.Operation + ". Problem: " + e.Detail.ProblemType); client.Abort(); Console.ReadLine(); } }
See more: http://msdn.microsoft.com/en-us/library/ms752208(v=vs.110).aspx
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Haixia_Xie Friday, February 28, 2014 6:51 AM
- Marked as answer by Bill_Yeager Friday, February 28, 2014 5:16 PM
Friday, February 28, 2014 6:50 AM -
Haixia, I very much appreciate your help :)
I modified my code, but am unsure how to throw the FaultException.
I have the following set up now on my service now:
I'm referencing a class that contains the DataContract as partially seen below. I think I would only need the applicationID and logeventType as the FaultException would seem to carry over the other properties I have listed. Please let me know if that is true.
namespace Ryder.Enterprise.DataTransferObjects { [Serializable, DataContract(Name = "LogEventArgs", Namespace = "http://www.Ryder.com/SOA/DataContracts/2014/02/17")] public class LogEventArgs { private string applicationID; private string method; private LogEventTypeEnum logEventType; private string exceptionMessage; private string innerExceptionMessage; private string stackTrace; private string source; [DataMember(Name = "ApplicationID")] public string ApplicationID { get { return applicationID; } set { applicationID = value; } } . . .
This is the method where I want to throw the FaultException. Syntactically, how would that look? Not sure how to place it in the Catch block or if even the Catch block is correct.
public bool UpdateSpotCheckInventory(SpotCheck transferObject) { bool blnUpdated = false; try { blnUpdated = SpotCheckCollectionGateway.UpdateData(transferObject); LogMessage.WriteEventLog("SpotCheck records updated successfully", "Ryder.ShopProcessService.SOA", 3, null); return blnUpdated; } catch (Exception ex) { //throw fault exception here on service return blnUpdated; } }
This is what I have on my client now. When the FaultException gets hit, it is transmitted back to the calling service and they would receive the exception message with the appropriate properties including the ex.Message, stacktrace, method, etc?
catch (FaultException<LogEventArgs> ex) { ex.Detail.ApplicationID = "ShopProcessService"; ex.Detail.LogEventType = LogEventTypeEnum.Error; serviceClient.Abort(); }
Finally, what would a Catch block look like on the receing end of getting the FaultException back from a service?Bill Yeager
Friday, February 28, 2014 2:23 PM -
Hi Bill,
It seems that you have got all of the answers from dhrumilapin this thread. :)
Best Regards!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Haixia_Xie Monday, March 3, 2014 6:42 AM
Monday, March 3, 2014 6:42 AM