WCF Fundamentals

 

 

WCF provides connections between two points; a WCF Client and a WCF Server which communicate via messages.

In order to communicate meaningfully the WCF programming model provides ways to indicate:

Address of the service - Where the service is located i.e. 

 

The binding mode of the services Indicates how to connect to the endpoint. WCF provides channels which carry the messages which include http, tcp, named pipes, perChannel, and MSMQ

 

The contract -  indicates the capabilities to be provided by the endpoint.The contract defines the class and the operations provided by the endpoint and the message format. The operations map to class methods that implement the endpoint including parameters passed to the methods.

 

Discoverability  A service may include a Metadata Exchange (MEX) endpoint, accessible by clients to obtain the Address, Binding and Contract of the service.

      The MEX returns the WSDL The MEX is called when a Service Reference is added from Visual Studio 2008 or by using the svcutil.exe at design time. After the WSDL is obtained, a client proxy class is defined and a app.config file is generated. The proxy class mirrors the signature o the endpoint operations enabling the client to simply instantiate and call the the class. The app.config file contains the service binding specifics.

 

Each service endpoint is hosted by an operating system and the host may be process such as a Web Server, or a Windows process.

The services implement certain behaviors using .Net attributes or manipulating the WCF runtime or through the configuration file.

 

A service can be implemented by using as many endpoints, all having defined an address, a binding and a contract.

 

Service Implementation

By default, WCF is configured to provide services via SOAP messages, threading, concurrency and instancing.

Implementation consists of defining a .NET class decorated with System.ServiceModel attributes. The System.ServiceModel namespace includes most of the WCF implementation and was provided with .NET 3.0.

 

Implementation involves the following steps:

 

Contract definition: Define a .NET useful class in C#/VB and decorate the class with [ServiceContract] attribute.

The [ServiceContract] defines in WSDL a PortTypeEach method that can be invoked on the service must be defined by the [OperationContract] attribute.

 

Endpoint definition: Specifies the service address, binding and contract by invokingAddServiceEndpoint() method on the ServiceHost class.

 

 

Implementation using Code only (continued...)