WCF: Hosting Service with multiple end points

In continuation of previous post regarding WCF, here goes another. In this post I will do step step explanation for hosting service using config file (remember this is the beauty of WCF, we don’t need to recompile to add multiple endpoints).

The assumtion is readers have already implemented the service contract. I will use a dummy class named IService for my explanation

  1. Create a instance of ServiceHost. 
    1. ServiceHost servicehost = new ServiceHost(typeof(Examples.ServiceImplementation));
  2. Use the Open to start listening.
    1. servicehost.Open();
  3. Now put the following in the App.Config file


Let me explain each of the element

  • The host element declares the base address for the endpoint. In this case its declaring two base address the http address and another one is the tcp address. The host address is used by the ServiceHost to listen on the respective port and address.


  • There are three endpoints


Each endpoint basically is collection of address, contract and binding. Here in the above case the address is not specified as we have already sepcified in the base address. The contract is Examples.IService and the binding is HTTP.

  • The second endpoint


is the TCP endpoint for the same service. Smilar to the previous one this definess the endpoint as collection of Examples.IService as contract and binding as TCP and address is not mentioned and taken from the base address.

  • The last endpoint


is used by the client to generate the meta information about the Service. This  is standard and ideally should be there for each service.I hope the above helps in understanding this beautiful technology.

The author has 10+ years experience with Enterprise Poduct Development. He is also the Co-Founder of PCVITA. He have expertise in Enterprise Architecture, Enterprise Messaging Platform Migration, Email Archiving.


3 Responses

  1. I am trying to create a service with two endpoints on one port, one http/text and on http/mtom streaming.
    The reason for doing so is to overcome the wcf message size limitation on large database queries, ie tens or hundreds of thousands of rows returned. So, to test two endopoints, i used the new wcf service library example, and added a second interface/contract, leaving as a simple function returning an int. When I have two simple endpoints on seperate contracts, the vs 2008 host tool WcfSVCHost.exe cant load either of them. But If I comment out all references to either, the remaining service/endpoint will load.
    Is it just wcfsvchost.exe, or wcf itself?

  2. Hi,
    Thanks for this – a LOT – it’s the closes example to my goal: a sample applet that shows connecting to WCF over a BROAD range of bindings, preferably NamedPipes, TCP, wsHttp, MSMQ and REST. My goal is to give students a glimpse at the potential of WCF and the challenges.

    A similar agenda can be found in this example: http://bdotnet.in/forums/t/1686.aspx

    But it excludes TCP connections and my attempts to add TCP to that project end in failure…

    My problem is I can’t get your example to work… When I try and the service in the service host through VS I get the following error:

    I’m using the latest WCF (4.0 and VS2010RC) bits.

    Any thoughts, links or references MUCH appreciated.

    Dave Gerding

  3. Hi
    I tried a lot of website but this one give a clear concept
    Amresh Chandra
    Comp 5 year in .net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: