What are contracts in WCF? In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does. WCF defines four types of contracts.

Service contracts

Describe which operations the client can perform on the service. There are two types of Service Contracts. ServiceContract - This attribute is used to define the Interface. OperationContract - This attribute is used to define the method inside Interface. [ServiceContract]interface IMyContract{ [OperationContract] string MyMethod( );}class MyService : IMyContract{ public string MyMethod( ) { return "Hello World"; }}Data contracts

Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.

There are two types of Data Contracts. DataContract - attribute used to define the class DataMember - attribute used to define the properties. [DataContract]

class Contact{ [DataMember] public string FirstName; [DataMember]

public string LastName;}If DataMember attributes are not specified for a properties in the class, that property can't be passed to-from web service. Fault contracts Define which errors are raised by the service, and how the service handles and propagates errors to its clients.

Message contracts Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.

Policy and BindingSpecifies the transport media such as HTTP or TCP. It aslo includes some of the securoty requirements. which are necessary for Commucation.What is the address formats of the WCF transport schemas?Address format of WCF transport schema always follow [transport]://[machine or domain][:optional port] format. for example: HTTP Address Format http://localhost:8888 the way to read the above url is

"Using HTTP, go to the machine called localhost, where on port 8888 someone is waiting" When the port number is not specified, the default port is 80.

TCP Address Format net.tcp://localhost:8888/MyService

When a port number is not specified, the default port is 808: net.tcp://localhost/MyService

NOTE: Two HTTP and TCP addresses from the same host can share a port, even on the same machine.

IPC Address Format net.pipe://localhost/MyPipe

We can only open a named pipe once per machine, and therefore it is not possible for two named pipe addresses to share a pipe name on the same machine.