Are SOAP faults inter-operable ?

 Posted by Akiii on 4/2/2012 | Category: WCF Interview questions | Views: 2947 | Points: 40
Answer:

Yes, SOAP faults are inter-operable as they are expressed to clients in XML form.

.Net exception classes are not good to be used in SOAP faults. Instead we should define our own DataContract class and then use it in a FaultContract.

public interface ICalculator

{
[OperationContract]
[FaultContract(typeof(MathFault))]
int Divide(int n1, int n2);
}


[DataContract]

public class MathFault
{
[DataMember]
private string operation { get; set; }
[DataMember]
private string problemType { get; set; }
}


public int Divide(int n1, int n2)

{
try
{
return n1 / n2;
}
catch (DivideByZeroException)
{
MathFault objMath = new MathFault();
objMath.operation = "division";
objMath.problemType = "divide by zero";
throw new FaultException<MathFault>(objMath);
}
}


Thanks and Regards
Akiii


Source: c-sharpcorner | | Alert Moderator 

Comments or Responses

Login to post response