The following is the contents of this article:
- The requirements to create an ENDPOINT
- What an Address is
- Brief on Binding
In earlier days a developer needs to do a lot of ground work to shape the communication architecture between the components, but now Microsoft provides WCF, a flexible programming framework that abstracts a lot of complexity in creating the services. So the communication foundation is already laid/available for the developers. It allows the developers to only concentrate on the problems. One of the finest benefits I saw in WCF is that the same business logic could be implemented in various protocols and transport options. So that your service can be exposed to any type of client.
With a simple and elegant example, I will just try to explain endpoints in WCF. Imagine that you are trying to send a birthday gift to your beloved ones living near your city. What exactly is the information you really need to send away? The first and the foremost is the address, where the gift needs to be delivered. And the second one is how wiil the gift be transmitted? What are all the transport options available to reach that address? By train or bus? And the last one you must know what is the content you are transmitting. What type of goods is it? Yes in WCF to define an endpoint ABC is required to establish the communication. A stands for Address, B stands for Binding and the C stands for Contract. Please try to match the ABC with the example I mentioned above, then you will understand what I mean. Anyway, we will discuss this topic in detail here. Once you define the ABCs, everything will be taken care of by WCF.
Address: Where exactly os your service hosted? In other words, what is the location of the service? An address could be an IP Address, server name, URL and so on.
The preceding is the format of an address. Whereas the first part is the transport schema, in our case HTTP is the transport schema, whereas the second part is the server location. In our case OnlineShoppingServer.com is the server location. And the next part is the PORT number where the server is listening for incoming requests. And the final part is the relative location of the resource on the server.
|Transport Protocol||Example Address|
|Microsoft Message Queue (MSMQ)||net.msmq://localhost|
|HTTP||It’s a protocol for communication over the web (uses TCP at a lower level).|
|TCP||High performance communication in WCF. Good for intranet scenarios.|
|Named Pipe||Fast and reliable communication between client and server running on the same machine.|
|MSMQ||Used when the client enqueues a message that a service can then consume later.|
WCF allows you to communicate with clients over any protocols mentioned above.
Based upon your project requirements, you can decide your transport protocol.
Binding: It is about how the messages are handled in the service side and the client side. Binding is a group of elements that correspond to the transport and protocol channels located in the channel stack. The channel stack is the sequence of channels that each passes through to the runtime execution. So what is transport, protocol channels? Let’s discuss here with a WCF Runtime execution diagram.
Transport Channel: As I mentioned in the diagram, the transport channel lies at the bottom of the stack, responsible for transporting messages from the client to the server using the transport protocols like HTTP, HTTPS, TCP, Named Pipes or MSMQ. The main responsibility is message encoding and transport.
Protocol Channel: It lies on the top of the transport channel. The protocol channel contains protocols like Security Protocol, Reliable Messaging and Transaction Protocol. Responsible for providing security features like authorization, authentication, protection and confidentiality.
The contract is an agreement between the client and the server about the structure and content of messages being exchanged. The Data Contract is about the structure of the message, whereas the message contract is about the content of the message being exchanged. If you need more details on the Data Contracts and the message contracts, please refer to my previous articles.
To reach an endpoint, the Where (Address), the How (Binding) and the What (Contract) are really important for establishing communication.