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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:07:36+00:00 2026-05-22T23:07:36+00:00

I have written a windows service in C# .NET. This windows service contains a

  • 0

I have written a windows service in C# .NET. This windows service contains a WCF service. I then use a new ServiceHost in the OnStart of the windows service to listen for messages for the WCF service. And close this ServiceHost in the OnStop.

When the service is running I can call the WCF service just fine. However, I then stop the service but can still call the WCF service. I wasn’t expecting this to happen. What is going on?

OnStart and OnStop code is below

    protected override void OnStart(string[] args)
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
        }

        serviceHost = new ServiceHost(typeof(MyService));

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

    protected override void OnStop()
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
            serviceHost = null;
        }
    }
  • 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-22T23:07:36+00:00Added an answer on May 22, 2026 at 11:07 pm

    I have now solved this and thought I would update with the answer. Although I doubt anyone else would be so stupid 😉

    I had added the reference to my client app by right clicking on the project and selecting “Add Reference” rather than “Add Service Reference”. I am still not sure why this allows the service to be called when it is not running but now I have added it as a Service Reference everything works as expected.

    Thanks for everyone’s input.

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

Sidebar

Related Questions

I have written a .NET Windows service which has a WCF service built into
I have a .NET Windows service which self hosts a WCF service. This WCF
I have a WCF service written in .NET 4.0 running on Windows 2008 R2
i have a windows service written in .net 4 which doing jobs periodically using
I have a WCF client application written in VB.NET 2008 as a Windows forms
We have written a custom windows service (VB.NET, .NET Framework 2.0) that takes a
I have a windows service written in C# .NET framework 3.5 and would like
Background: I have a .NET 4.0 web service running on Windows Server 2008 written
I have a Windows Service written in .NET C# which calls a COM component.
I have a windows service written in C#.Net. When the service is started, I

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.