WCF Series - Basics of WCF

In this article we will learn about the Basics of Windows Communication Foundation.

In this post we are going to discuss the following Building Blocks:

  1. Services
  2. Service and Data Contracts
  3. EndPoints
  4. Bindings

Services:

A Service is a collection of operations that are exposed so that the Client can call them and execute them. This is true whether the Service is a WCF service or a Web service.

Service Contracts:

Service Contracts defines what operations are available and how clients use them.

Data Contracts describes the data that the Client and the Service exchange.

So the Service Contracts describes not only the Operations supported by the Service but also the message exchange pattern used and the format of the message.

Message exchange pattern means whether the client calls the Service and expects a response or the Client calls the method and does not expect a response.

The ServiceContract attribute marks an interface as a Service Contract.

The OperationContract attribute exposes methods of the interface.

Data Contracts:

Data Contract describes how the CLR Types are mapped to XSD schema definitions.

That enables Complex Types to be serialized and deserialized so they can be passed back and forth.

For Example:

[DataContract]
Public class Customer
{
[DataMember]
Public string CustomerId {get ; set ;}
}

EndPoints:

Host application make the Service available by providing one or more endpoints to Clients.

Endpoint consists of:

  • Address of Service ( Where is the Service ? )
  • Binding supported by service (How do you reach it ?)
    - Can include transport protocol, security and transactional requirements.
  • Contract implemented by Service (What can you do with it ?)
    - ServiceContract attributed interface .

These are together known as the ABC's of Windows Communication Foundation.

Client and Service use the same endpoints to communicate with each other.

Bindings:

Bindings specify how a service endpoint communicates with the Client Endpoints.

A Binding consists of several Binding elements describing some aspect of communication.

For Example: 

How do the messages Transpost? Are they moving over HTTP or do they use TCP protocol for communication?

What are the Protocol requirements? Security, reliability, Transactions etc.

Message Encoding ( text, binary, etc )

Can be created in the Config file and also dynamically in the Code .

WCF Provided Bindings:

WCF provides us with various Bindings with each one of them supporting a particulat type of operation.

BasicHttpBinding:

BasicHttpBinding is compatible with ASMX – Web Services.

WSHttpBinding:

Conforms to WS-* specifications for reliability, security and transactions .
Visual Studio uses this Binding by Default. So if you create a service this would be the Binding the Visual Studio would use. Check out the screenshot below:

WCF.gif

WS2007HttpBinding:

Conforms to OASIS specifications for reliability, transactions and security .

WSDualHttpBinding:

Supports WS-*plus two way communication. So this is a extension of WSHttpBinding with two way communication. So if you want the Server to call back to the Client you use this Binding.

WSFederationBinding:

Supports the WS-Federation specification for sharing identities across multiple systems.

In the next post we will start out creating a much more enhanced WCF Service. Till then,

Happy Coding.