Showing posts with label Fault Exception in WCF. Show all posts
Showing posts with label Fault Exception in WCF. Show all posts

Wednesday, March 24, 2010

Fault Exception in WCF

calling the FaultException in Catch block

catch (Exception ex)

{

throw ex ;

// useful when FaultException attribute is mentioned in the web method called.

//with method declaration in interface.

////[FaultContract(typeof (MyFaultException))]

//MyFaultException myException = new MyFaultException();

//myException.Reason = "Reason for this error is : " + ex.Message.ToString();

}

Fault exception definition

// optional but a good practice.

[DataContract]

public class MyFaultException

{

private string _reason;

[DataMember]

public string Reason

{

get { return _reason; }

set { _reason = value; }

}

}