1

I have some confusions around choosing the return parameters for my WCF service. The service is basically is account registration service where the consumers(legacy consumers too!) need to pass the user detail information. The service will validate the user details like name, address, ssn validations etc. If all validation passes, i need to pass true else false with list of error codes and corresponding error messages.

For this, currently i have defined a data contract class Response like below,

[DataContract]
    public class Response
    {


        [DataMember]
        public bool Result
        {
            get;         
            set;

        }

        [DataMember]
        public IList<Error> ErrorList
        {
           get;         
           set;
        }
    }


    [DataContract]
    public class Error
    {

        [DataMember]
        public int Code
        {
            get;         
            set;
        }
        [DataMember]
        public string Description
        {
            get;         
            set;
        }
    }

My doubt: I was reading the following thread, WCF - Faults / Exceptions versus Messages

It says that we need to return FaultContract for returning these type of error/validation messages. I have understood that FaultContract are designed for sending exceptions to the consumers for interoperability. If this is the case, i agree we need to send FaultContract if there are some unhandled exceptions, for ex: if communication failed between webserver and DB server, etc.

Please advise me on this...Do i need to send FaultContracts or like the above Response object in these scenarios???

I feel returning Response object is correct because these are all some business validation which is not an exception...pls correct me if i am wrong.

Thanks in advance!

Regards, Bala

Community
  • 1
  • 1
Bala
  • 333
  • 1
  • 5
  • 13

1 Answers1

1

You should send Response object back as the reply and on your operation contract, you can specify what kind of fault contract can be thrown. By sending fault contract, even though it's an exception, the channel will not be faulted, you can still use it; otherwise, the channel can be faulted and you can't use it any more.

Jack
  • 717
  • 5
  • 4