Config-less Hosting

Hi Friends,

In this section, we will look at Config-Less Hosting.

WCF does not require config file. It only requires endpoint information. It does not matter which medium it is coming from. You can provide all these information from the code itself. You can get all mandatory information from some source say xml file or database to construct the endpoint. I will give the demo by simply hardcoding the same. Let us go to console hosting. Nevertheless, before making any change in code, let me just comment the config section for WCF in APP.config file. Below is the snippet in the finished state.

Let me explain the code a bit. As you can see, I have provided endpoint procedurally. One point to note here is that all of these binding classes inherit from common base class binding. Here, I have created an instance of NetTcpBinding. Then I instantiated a type of my contract. In the end, add I have added endpoint with AddServiceEndpoint method. With the above code change in place, when I build and run the same, it produced the below output.


Similar thing can be achieved with web host as well. We will delve further in the coming section. Till then, stay tuned and Happy Coding,

Happy Coding

1,037 total views, 2 views today

2 thoughts on “Config-less Hosting

  1. this is good but … since we hardcode the port i cannot do the dev/test/prod scenario here i.e. as a developer when developing this on my system – i would like to host on port X. As a testing team they might want to host it on port Y and when it comes to production you as a dev never have a say :) the IT takes over … what i would have done is – have a app setting key which will define the port to host this on. By default the value will be what a dev wants. But when a testing team or deployment team deploys this one of the instruction will be to change the port accordingly …. just my observation …
    Lohith recently posted…Setting up Easy Tables in Azure App Service Mobile AppsMy Profile

    • I just noticed your comment now as your comments doesn’t fall under moderation queue, hence didn’t realize. Yup the point is crystal clear. This is how syncing happens between environments entirely driven by X number of ports for different environments.

Comments are closed.