I have a simple WCF service hosted in a console app and what I would like to do is display the app.config information such as the base address and endpoint information on the console without using hard coded values in the code.
Is this at all possible? It sounds like a reasonably plausible scenario in a production environment where the application is interested in how the config has been set-up?
Here’s the host code…
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(ServiceImp.ServiceA)))
{
host.Open();
// I would like to display info here
// Console.Writeline ("Service hosted @ baseadress...., endpoint ABC is...");
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate Host");
Console.ReadLine();
}
}
}
Googling only seems to suggest using ConfigurationManager.AppSettings, but this can only access the AppSettings not the System.ServiceModel content.
Thanks in advance
Access to the configuration is provided via the
System.ServiceModel.Configurationnamespace. However, if theServiceHostinstance is already open, you can also access most information via it.Examples:
Just explore the
ServiceHostclass, in particular theDescriptionproperty.