http://myview.rahulnivi.net/getting-started-angular-js/
Tuesday, February 16, 2016
Config-less Hosting
Hi guys,
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.
| using System; | |
| using System.ServiceModel; | |
| using System.ServiceModel.Channels; | |
| using MovieLib.Contracts; | |
| using MovieLib.Services; | |
| namespace ConsoleHostApplication | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| ServiceHost hostMovieManager = new ServiceHost(typeof(MovieManager)); | |
| string address = "net.tcp://localhost:8010/MovieService"; | |
| Binding binding = new NetTcpBinding(); | |
| Type contract = typeof (IMovieService); | |
| hostMovieManager.AddServiceEndpoint(contract, binding, address); | |
| hostMovieManager.Open(); | |
| Console.WriteLine("Service Launched,Press Enter to Exit!"); | |
| Console.ReadLine(); | |
| hostMovieManager.Close(); | |
| } | |
| } | |
| } |
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,
Thanks,
Vijay Kumar Kandala.
Happy Coding
Vijay Kumar Kandala.
Happy Coding
Subscribe to:
Comments (Atom)
