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.
My goal here is to use netTcpBinding with this web-hosting. Therefore, if I simply go ahead and change the binding in my web.config file, then it will result me the below error. However, the same can be achieved with the help of WAS.
In this section, we will discuss Web Hosting. Now, in case of Web-Hosting IIS is going to all our hosting. It instantiates and manages the ServiceHost instance automatically. One point to note here that IIS is limited to HTTP. Nevertheless, with the use of WAS (Windows Application Services) we can use other bindings as well. Without, WAS we are using IIS for external web services. In WCF, we used to require .SVC file for browsing point. However, with .NET 4.0 onwards this need has been eliminated. Now, the same thing can be achieved virtually with configuration itself that we will see in a moment.
Hosting is the key ingredient to give life to your service. Without a host, service holds no meaning. Host is the application, which is responsible for listening the calls and then instantiating the service. WCF offers two types of hosting; one is called Web-Hosting which is there since web service days. Few artifacts about this is easy to setup, dependency on IIS and only supported protocol is HTTP. There is a catch involved in this. We will cover the same in coming section. Now, another hosting scenario is Self-Hosting. Self-Hosting covers any application. Any application can be host. It requires little bit of coding but gives very deeper control over your hosting. With this, you can setup custom hosting, which will feature rich. So, without wasting time let us get started.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Subscribe For Latest Updates!
Signup for My View newsletter and get notified when I publish new articles for free!