Getting Started with WCF – Part 3

Hi Friends,

In today’s post i will talk more about Endpoints and Services. So, basically in the last session we saw how to write a simple WCF program and host the same. So, basically with WCF we write services which expose end points to the outside world. Here, our service implementation will define the actual business logic and endpoints define the communication logic. Basically, endpoints serve various communication logic. We’ll see some of these in some time. Now, below is the diagram which explains the relationship between services and endpoints. So, basically services expose multiple endpoints to it’s consumers and consumers then utilize this service via endpoint.

Picture12

Now, the question arises here is that what is an Endpoint? well endpoint is basically an information that tells WCF how to setup communication channel. Now, each endpoint address consists of three Major things.
Now, below is the diagram which shows the actual meaning of endpoint in a nutshell.

Picture9
EndPoints consist three major things. These are

Address:- Basically tells where to send the messages.
Binding:- How to send them.
Contract:- What messages will contain.

Now, these are basically A,B,C of WCF. Address defines network address for sending and receiving messages. Here, WCF runtime will produce a communication channel which will be served as listener for these messages. Then comes the binding which defines the protocol for how to send messages like it specifies what kind of Transport Protocol needs to be used, what message format and what WS-* protocol you want to use. Then, we have Contract, which tells what the messages must contain. So, each endpoint contains three basic information. Hence, services exposes endpoints and client consume them.

Now, let’s discuss binding in detail. In the below table, you can see some of the built in bindings and it’s usage scenarios.

Picture10

So, as you see in the table 1st three bindings all use HTTP. So, here Transport mechanism is also associated with the binding name. The 1st one provides Restful style communication whereas other two provides SOAP style communication. We’ll understand all these styles of communication in detail in coming sessions. Now, one important point to note here that these 1st three bindings are meant for interoperability which means they will use XML message format for communication.Now, the remaining bindings shown here are basically not meant for interoperability. Basically, they assume that WCF is used on both sides as these bindings are .Net Specific. That is why their naming also begins with net which means .Net to .Net communication. Now, irrespective of these built in bindings, you can always write your custom binding which could be a mix of these built in bindings. By the way, before selecting any binding you should always know which one would be best suited in your case.

Now, let’s see the process of consuming WCF Service. Now, in order to consume the WCF service, client need to know several things like

Where to send the message
How to send the message
Then what the messages are going to contain

So, basically these are the endpoints of any WCF service. So, in order to consume any WCF service client need to know the endpoint of that particular service. Now, below is the most generalized description from the higher level which shows how communication happens.

Picture11

Now, with WCF we consume services via channels. Below, is the labeled diagram explaining how clients consume WCF service.
Picture14

Now, channels are basically built based on endpoints. Now, here, the client has to retrieve the endpoint definition from service metadata. Now, as you can see in the diagram we have a Service which is exposing multiple endpoints. I have shown in diagram two endpoints but it can be any number. Then, let’s suppose client wants to talk to this service via this endpoint. Then, in order to do so, client has to request metadata or WSDL definition from the service. Now, once metadata is available to the client, client will run one metadata import tool which will produce client side version of the endpoint. Now, once client has endpoints available; client can then go ahead and construct the channel based on one of the endpoints. And, once the channel has been constructed, client can send message through that channel to the service. So, basically WCF provides nice symmetrical architecture on both sides of the wire.

So, in this session we have seen closely about endpoints, services and then how to consume services theoretically. We will see all these practically in coming sessions. Till then stay tuned and Happy Coding.

Thanks,
Rahul

2,055 total views, 2 views today