The ABC of Windows Communication Foundation
“ABC” is the WCF mantra. “ABC” is the key to understanding how a WCF service endpoint is composed. Think Ernie, Bert, Cookie Monster or Big Bird. Remember “ABC”.
Web services zealots who read Web Service Description Language (WSDL) descriptions at the breakfast table will easily recognize these three concepts as the three levels of abstraction expressed in WSDL. So if you live in a world full of angle brackets, you can look at it this way:
“ABC” means that writing (and configuring) a WCF service is always a three-step process:
A contract is an agreement between two parties. It defines how a client should communicate with your service. In other words a contract is a platform and standard way of describing what the service does. There are the following four types of contracts in WCF Service Contract :
we've already used Data Contract and Operation Contract.
Service contracts define the Interface for the service
An Operation Contract defines the method exposed to the client to exchange the information between the client and server. An Operation Contract describes what functionality is to be given to the client, such as addition, subtraction and so on.
Data Contracts define the data type for variables that are the same as get and set properties but the difference is that a Data Contract in WCF is used to serialize and deserialize the complex data. It defines how data types are serialized and deserialized. Using serialization, you can convert an object into a sequence of bytes that can be transmitted over a network. Using de-serialization, you reassemble an object from a sequence of bytes that you receive from a calling application.
A Fault Contract handles the exception and understands the cause of the error that occurs in the WCF service. When we develop a managed application or service, we will handle the exception using a try- catch block, but these exceptions handlers are technology-specific.
The default SOAP message format is provided by the WCF runtime for communication between the client and the service. If it does not meet your requirements then we can create our own message format. This can be done using the Message Contract attribute.
Create a calculator service that implement add and sub operations on complex numbers instead of numerical ones. This justifies to introduce DataContract for the Complex number Type.
In the Add operation, throw general exception and send exception information from service to client with FaultException.