Thursday, May 12, 2011

Importance of Fault contact in web service.

I have gone through some articles about the importance of fault contract in SOA.
I got this perception that fault contract is not only necessary for the client but it also more describe your service.

Fault contract is a very good approach to describe the possible error so , client will know in advance and safe to face any surprise behavior. Client can handle this exception and write his logic because he is well aware about, what will happen after anything wrong.
Now the question come how we can implement fault contract.
There could two (2) ways implement it.
1) specify it in wsdl document.
2) make your own exception.

Lets discuss one by one.
1) specify it in the wsdl
One of the best approach to define you contract first before writing any code, there is debate on code first vs. contract first approaches. Everyone accepts contract first approach is very detail and less prone to error approach. As the matter of fault contract we can define in code or contract both will resolve at the end in wsdl.
Advantage of this approach is:
"SOAP faults are message types that are included in the metadata for a service operation and therefore create a fault contract that clients can use to make their operation more robust or interactive. In addition, because SOAP faults are expressed to clients in XML form, it is a highly interoperable type system that clients on any SOAP platform can use, increasing the reach of your WCF application. "
This is excerpt of msdn article.
This is not a new concept to define fault contract wsdl specification has this leverage to define your faults inside wsdl document. For more …
Fault contract implementation in wsdl by IBM

2) Make your own exception
This is also good approach and specially when previously established who uses custom exception Scheme. Its good for them this scheme to use it without disturbing the whole application. It comes with its own cost also because Exception will be serialized in to SOAP request. Because the behavior is not defined at designed time