Tuesday, 24 July 2012

WCF Tutorial -Contracts


WCF (Windows Foundation Communication) is a platform can be used to build service oriented applications.
We can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data.

WCF has following core contracts

·         Service Contract
o    A service contract specifies the signature of a service, it defines the operations available to the service to be invoked, the data it exchanges, and other contractually required data
·         Operation Contract
o   Operation Contracts are the methods which are exposed in the service.
·         Data Contract
o   Defines the structure of the data included in the payloads of the messages flowing in and out of the service.
·         Message Contract
o   Enables you to control the headers that appears in the message and how the messages are structured.
·         Fault Contract
o   WCF enables you to specify the fault behavior of your service, when your service might issue faults and what type of information will be sent with the fault.

WCF Basics

Service.Servicemodel is the namespace to specify the behavior of WCF Service. While Defining WCF Service we have to take care of following aspects.

1.      How service behaves and what operations it exposes
2.      When service might issue faults and what kind of fault it might issue.
3.      What MEPs are required to interact with the service operations will be one-way two- way etc.

Three core types of WCF contracts map directly to a corresponding web service standard in the following way.

Service contract map to WSDSL
Data contract map to XSD
Message contract map to SOAP

No comments: