home / software / tips and tricks / Basics of WCF

Basics of WCF

Updated:  07/04/2013 04:07 AM
Author:  Shiju Mathews

Status:    Resolved.



What are the basics of WCF?
<<   PreviousNext Chapter >>
 


Following are the basics of WCF.

1. EndPoint


   Endpoint is a portal for WCF to communicating with the world. All the WCF communications are take place through end point. Endpoints provide clients access to the functionality offered by a WCF service.

End point consists of three components.  

(a) Address
   Basically URL, specifies where this WCF service is hosted .Client will use this url to connect to the service.
e.g http://localhost:8090/MyService/SimpleCalculator.svc

(b) Binding
   Binding will describes how client will communicate with service. There are different protocols available for the WCF to communicate to the Client. You can mention the protocol type based on your requirements.
A binding has several characteristics, including the following:

A binding has several characteristics, including the following:

Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols.

Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K).

Protocol(Optional) - Defines information to be used in the binding such as Security, transaction or reliable messaging capability


(c) Contract
The contract is a platform-neutral and standard way of describing what the service does.
Collection of operation that specifies what the endpoint will communicate with outside world. Usually name of the Interface will be mentioned in the Contract, so the client application will be aware of the operations which are exposed to the client. Each operation is a simple exchange pattern such as one-way, duplex and request/reply.

WCF defines four types of contracts.

1. 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.


2. Datacontracts: 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.


3. Message Contract
Default SOAP message format is provided by the WCF runtime for communication between Client and service. If it is not meeting your requirements then we can create our own message format. This can be achieved by using Message Contract attribute.
To know more on Message Contract see Message contract tutorial.

4. Fault Contract
Suppose the service I consumed is not working in the client application. I want to know the real cause of the problem. How I can know the error? For this we are having Fault Contract. Fault Contract provides documented view for error occurred in the service to client. This helps us to easy identity, what error has occurred.

Tags: Basics of WCF
Updated on: December 2024