Microsoft's next-generation programming platform and runtime system for building, configuring and deploying service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments. Most of the WCF functionality is included in a single assembly called System.ServiceModel.dll, located in the System.ServiceModel namespace.
What are the ABCs of WCF?
ABC stands for address, binding, and contract, they are also called WCF endpoint.
- A - stands for Address: Where is the service?
- B - stands for Binding: How do I talk to the service?
- C - stands for Contract: What can the service do for me?
Address: The address provides two important elements: the location of the service, and the transport protocol.
WCF supports the following transport schemas:
Here are few sample addresses.
Binding: Bindings are objects that are used to specify the communication details that are required to connect to the endpoint of a WCF service. It is the primary extension point of the ABCs of WCF. Bindings describe the transport protocol, message-encoding format and other messaging protocols for the communication channel. Here are complete list of the standard bindings that come with WCF.
|Binding type ||Description |
|BasicHttpBinding ||The BasicHttpBinding is able to communicate with ASMX-based Web services and clients such as ASP.NET web services (ASMX). |
|WSHttpBinding ||The WSHttpBinding is similar to the BasicHttpBinding but provides more Web service features such as distributed transactions and secure, reliable sessions. |
|WSDualHttpBinding ||The WSDualHttpBinding provides the same support for Web Service protocols as the WSHttpBinding, but it provides two-way communication. |
|WSFederationHttpBinding || |
A secure and interoperable binding that supports federated security. Federation is the ability to share identities across multiple systems for authentication and authorization.
|NetNamedPipeBinding ||A connection-oriented binding for communications on the same machine over named pipes. |
|NetTcpBinding || |
A secure, reliable binding suitable for cross-machine communication.
|NetPeerTcpBinding || |
Provides a secure binding for peer-to-peer network applications.
|NetMsmqBinding || |
Represents a queued binding that is suitable for cross-machine communication.
|MsmqIntegrationBinding ||This binding can be used to enable WCF applications to send and receive messages to and from existing MSMQ applications that use legacy MSMQ components. |
Bindings can be defined in two ways:
Declaratively, using service model configuration settings, Here is a declaratively sample:
binding="basicHttpBinding" contract="ITestService" />
Programmatically, by adding endpoints to the ServiceHost, Here is a programmatically sample:
In programmatically, As you can see we construct a binding instance and assign its endpoints.
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.None;
Uri baseAddress = new Uri("http://localhost:8001/TestService");
Uri address = new Uri("http://localhost:8001/TestService/TestService");
ServiceHost serviceHost = new ServiceHost(typeof(TestService), baseAddress);
serviceHost.AddServiceEndpoint(typeof(ITestService), binding, address);
Contract: A contract is a description of the messages that are passed to and from service endpoints.
There are three types of contracts in WCF:
Service contracts: Describe which operations the client can perform on the service. It defines some properties about the service, and a set of actions called Operation Contracts. Operation Contracts are equivalent to web methods in ASMX technology. Here is a sample of service contract.
<%\@ ServiceHost Language="C#" Service="TestService" %>
public interface ITestInterface
string Test ( string message);
public class TestService : ITestInterface
public string Test ( string message)
return "Hello: " + message;
Data contracts: Data contracts describe data structures that are used by the service to communicate with clients. A data contract maps CLR types to XML Schema Definitions (XSD) and defines how they are serialized and deserialized. Data contracts describe all the data that is sent to or from service operations.
public event EventHandler TestEvent;
Message contracts: Message contracts describe the structure of SOAP messages sent to and from a service and enable you to inspect and control most of the details in the SOAP header and body.
public class BidPrice
public DateTime CurrentTime;
public Price Price;
In this article, we examined WCF as a very rich technology platform for building distributed systems. WCF Services expose a collection of Endpoints where each Endpoint is a portal for communicating with the world. Each Endpoint has an Address, a Binding, and a Contract (ABC). The Address is where the Endpoint resides, the Binding is how the Endpoint communicates, and the Contract is what the Endpoint communicates.