Contracts in WCF

WCF defines 4 Types of Contracts:

1. Service Contract: Service Contract is an interface or a class that defines the service contract in a Windows Communication Foundation (WCF) application. A service contract is the gateway to a service for external applications to make use of the service functions, and at least one service contract should be available in a service.


2. Data Contract: Data Contract defines a type with a set of data members or fields that will be used as the composite type or data members in a service contract.


3. Message Contract: A Message Contract is used to control the structure of a message body and serialization process. It is used to send/access the information in the soap header. Using a Message Contract, we can customize the parameters which is sent using a SOAP message between the client and the server. The SOAP header is implemented in the namespace system.web.services.protocol.


4. Fault Contract: When any WCF service throws an exception, then the client cannot be notified directly of about exception. Because whenever an exception is thrown from a service, it cannot be sent to the client. So if we want to get actual exception which is occured in service functionality then a fault contract can be used as shown below.



No comments:

Post a Comment

What are different Transaction Isolation Levels in WCF?

Here, the [Service Behavior] attribute specifies the Transaction Isolation level property.  Transaction Isolation specifies the degr...