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 8262019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:37:07+00:00 2026-06-08T03:37:07+00:00

I have a WCF service hosted in a consol application(that also acts as the

  • 0

I have a WCF service hosted in a consol application(that also acts as the Windows Service installer), pleas see more here : http://msdn.microsoft.com/en-us/library/ms733069.aspx

This is how the class in the consol application looks like :

public class MyAppWindowsService : ServiceBase
    {
        public ServiceHost _MyAppClientServiceHost = null;
        public ServiceHost _MyAppIntegrationServiceHost = null;
        public ServiceHost _MyAppserviceHost = null;

        public MyAppWindowsService()
        {
            // Name the Windows Service
            ServiceName = "MyApp Service";
        }

        public static void Main()
        {
            ServiceBase.Run(new MyAppWindowsService());
        }

        private void StopService(ServiceHost serviceHost)
        {
            if (serviceHost != null)
            {
                  serviceHost.Close();
                  serviceHost = null;
            }
        }
        private ServiceHost StartService(Type serviceType)
        {
            ServiceHost serviceHost = null;

            // Create a ServiceHost for the CalculatorService type and 
            // provide the base address.
            serviceHost = new ServiceHost(serviceType);

            // Open the ServiceHostBase to create listeners and start 
            // listening for messages.
            serviceHost.Open();

            return serviceHost;
        }
        private void StartServices()
        {
            StopService(_MyAppClientServiceHost);
            StopService(_MyAppIntegrationServiceHost);
            StopService(_MyAppServiceHost);

            _MyAppClientServiceHost = StartService(typeof(MyApp.ServiceImplementation.MyAppClientService));
            _MyAppIntegrationServiceHost = StartService(typeof(MyApp.ServiceImplementation.MyAppIntegration));
            _MyAppServiceHost = StartService(typeof(MyApp.ServiceImplementation.HL7Service));
        }
        private void StopServices()
        {
            StopService(_MyAppClientServiceHost);
            StopService(_MyAppIntegrationServiceHost);
            StopService(_MyAppHl7ServiceHost);
        }

        // Start the Windows service.
        protected override void OnStart(string[] args)
        {
            StartServices();
        }

        protected override void OnStop()
        {
            StopServices();
        }

    }

This is made for running in a Windows Service, how do I make so I can run this as a regular selfhost in debug mode(during development)? or do I really have to start a special project to be able to debug this servuce during runtime?

Edit:

I decided to use the existing windows service project but change the main to something like this :

public static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.WriteLine("--- MyApp Services ---");
                Console.WriteLine("Starting services...");
                Instance.StartServices();
                Console.WriteLine("--Finished--");
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                Instance.StopServices();
            }
            else
                ServiceBase.Run(new MyAppWindowsService());
        }
  • 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-06-08T03:37:09+00:00Added an answer on June 8, 2026 at 3:37 am

    This is what I do

    Solution A

    • Install a Windows Service using InstallUtil from my Debug\bin folder
    • Stop and start service using sc start or sc stop
    • Once service started do Debug > Attach to Process… and attach VS to the service

    Solution B

    Have a Debugger.Break call on the first line of the OnStart method.

    Solution C

    Add a temp separate console application that does the same job as your service.

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

Sidebar

Related Questions

I have a WCF service that is hosted in a windows application. The service
We have created a WCF service hosted in a windows service that handles Authentication
I have a wcf service library that is hosted in a windows service. I
I have a WCF service hosted in a Windows Forms application (.NET C# 4).
I have a WCF service that is hosted on a c# console application. Is
I have an wcf service that is hosted in II6. The service uses the
I have a WCF service that needs to hosted using basicHttpBinding using SSL. So
assume I have a hosted wcf service in a console application like this: public
I have a WCF service hosted on my local machine as windows service. Now
Hi, I have a WCF service hosted in IIS7 that runns the following code

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.