locked
Custom FaultExcetion to SOAP format in WCF RRS feed

  • Question

  • Hello,

    I have custom Message contract and want to convert to SOAP on client side. Here is my message contract.

    public string GetData(int value)
            {
                int a = 1;
                int b = 0;
                try
                {
                    return (a/b).ToString();
                }
               
                    catch (Exception ex)
                    {
                        throw new FaultException<ABCSTransactions>(new ABCTransactions { Amount = 10000.50, accountNumber = "AC98765}, new FaultReason("An error occurred during a WCF call, see inner Detail for more info! ---" + ex.ToString()));
                    }
            }

    [MessageContract]
        public class ABCTransactions
        {
            [MessageHeader]
            public string  accountNumber;
            [MessageHeader]
            public double Amount;

        }

    Client side code:

     catch (FaultException<ABCTransactions> abctran)
                    {

                 // How to get SOAP format

                    }

    Sunday, March 3, 2013 2:43 AM

Answers

  • Hi,

    If you want to return custom error message, you can make use of FaultContract to achieve the goal, create an instance of the fault contract and initialize it with information that should be returned to the client application in the operation of the service implementation, then throw a new FaultException<T> using the FaultContract for generic type T. Check document below for more information.

    #How to: Return Custom Error Messages Using FaultContracts

    http://msdn.microsoft.com/en-us/library/ff650547.aspx

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Haixia_Xie Monday, March 11, 2013 9:55 AM
    Monday, March 4, 2013 6:10 AM