Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:17:39+00:00 2026-05-28T04:17:39+00:00

I have a simple WCF service hosted in a console app and what I

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:17:40+00:00Added an answer on May 28, 2026 at 4:17 am

    Access to the configuration is provided via the System.ServiceModel.Configuration namespace. However, if the ServiceHost instance is already open, you can also access most information via it.

    Examples:

    // BaseAddress
    Console.WriteLine(serviceHost.BaseAddress);
    
    // Endpoints (non-MEX)
    foreach (ServiceEndpoint ep in serviceHost.Description.Endpoints)
    {
      if (serviceHost.BaseAddress.Any(uri => uri.Equals(ep.ListenUri) &&
          ep.Contract.ContractType != typeof(IMetadataException))
      {
        Console.WriteLine("ListenURI: " + ep.ListenUri);
        Console.WriteLine("  Name   : " + ep.Name);
        Console.WriteLine("  Binding: " + ep.Binding.GetType().FullName);
      }
    }
    
    // List of MEX endpoints:
    foreach (ServiceEndpoint ep in serviceHost.Description.Endpoints)
    {
      if (ep.Contract.ContractType == typeof(IMetadataExchange))
      {
        Console.WriteLine(ep.ListenUri.ToString());
      }
    }
    

    Just explore the ServiceHost class, in particular the Description property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple console app that calls a WCF service over net.tcp and
I have a simple self hosted WCF Console windows app, and I can connect
I have a simple WCF Web service. It's hosted on IIS under the default
I have a simple WCF service hosted in IIS7.5 exposed over a wsHttp binding
I have simple WCF service hosted on Windows Service. When the client of wcf
I have a simple WCF service (hosted as its own site in IIS). It
I have a simple WCF service hosted in a windows service. The service itself
I have a simple .NET 4 WCF service which I have hosted locally on
i am new to wcf. i have created and hosted simple wcf service on
I have a simple WCF service: public Order[] GetOrdersByStatus(int statusid) { OrderService os =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.