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

  • Home
  • SEARCH
  • 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 304431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:16:48+00:00 2026-05-12T07:16:48+00:00

I am having some trouble hosting a WCF service inside a Windows Service. I

  • 0

I am having some trouble hosting a WCF service inside a Windows Service.
I can start my WCF service in VS2008 and by navigating to the base address in my app.config

<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="WCF.IndexerBehavior"
        name="WCF.Indexer">
        <endpoint address="" binding="wsHttpBinding" contract="WCF.IIndexer">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" 
contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/WCFService/Action/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WCF.IndexerBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

I can see it works fine, I get the page saying I created a service and code samples on how to use it are shown.

Now my next step was to create a Windows Service to host my WCF shown above.

I just used te windows service template, it gave me a Program.cs and Service1.cs which I renamed to WindowsServiceHost.cs. In it I have:

private ServiceHost host;

        public WindowsServiceHost()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                var serviceType = typeof(Indexer.WCF.Indexer);
                host = new ServiceHost(serviceType);
                host.Open();
            }
            catch (Exception ex)
            {

            }
        }

        protected override void OnStop()
        {
            if (host != null)
            {
                host.Close();
            }
        }

Everything compiles fine, I can run InstallUtil (I defined an installer).
The service used to start and stop immediately but disabling Windows Defender got rid of this.
Now the service starts (As a network service) and stays up (I think), but when I navigate to the base address, I get the not found page.
Another weird thing is when I try to stop the service (which is still displayed as running) I get:

Error 1061: The service cannot accept control messages at this time

I’ve tried everything but am at a loss.

  • 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-12T07:16:49+00:00Added an answer on May 12, 2026 at 7:16 am

    Not 100% sure what the reason really is – just to confirm, we self-host WCF services in Windows services all the time and it generally works perfectly fine.

    Two points you could try – just to get a feeling for the behavior and a potential clue for the problem:

    1) I notice you open the ServiceHost with just the type of the service – that works, but you might still want to add a base address even to the call of the new ServiceHost() – like this:

    host = new ServiceHost(serviceType, 
                           new Uri("http://localhost:8181/WCFService/Action/");
    

    Can you navigate to that address and get the service page??

    2) The other thing I noticed is that your service seems to be called Indexer.WCF.Indexer as specified in the typeof() before opening the host, but in the config file, the name= on the <service> tag is only “WCF.Indexer”.

    Could you possibly try to change that tag to read:

    <service behaviorConfiguration="WCF.IndexerBehavior"
             name="Indexer.WCF.Indexer">
    

    Does that help? Are you now able to see the service page when navigating to it in the browser?

    Marc

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

Sidebar

Related Questions

I'm having some trouble figuring out why I can only get the children of
Im having some trouble findig a way to validate a url on my app.
After having some trouble with setting up a thread to start my MIDI sequencer
I'm having some trouble with Instruments. My app is working perfectly without crashes, but
having some trouble with this can't understand why it won't work properly. http://host.philmadelphia2.com/~clare/order/ when
Im having some trouble with a simple form. I can't seem to prevent the
Im having some trouble with Jquery Templates and can't seem to figure out what's
im having some trouble with the following code: Ext.define('...controller...', { extend: 'Ext.app.Controller', init: function()
Having some trouble with what should be a very simple scenario. For example purposes,
Hey having some trouble trying to maintain transparency on a png when i create

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.