Maverick

Friday, February 1, 2008

WCF: Hosting Service with multiple end points

Filed under: .NET Framework, C#, SOA, WCF — debasishpramanik @ 8:12 pm
Tags: , , ,

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

config1.gif

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.

host.gif

  • There are three endpoints

http.gif

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

tcp.gif

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

mex.gif

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.

1 Comment »

  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?

    Comment by BillInPA — Monday, September 8, 2008 @ 11:53 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.