views:

451

answers:

2

I'm trying to host a WCF Service inside a Windows Service which I am starting through a console app. Each service is its own project as is the console app. I've copied the app.config from the WCF Service library into the app.config of the console app, but I keep getting "Service has zero application endpoints...". I've read in a few places that the error means my type references are not fully qualified, but I've double (triple, quadruple...) checked that. And I'm pretty sure I have an app.config. There are 3 exes in my debug directory: Console App, Console App vshost, Win Service. The Win Service didn't have an app.config, so I tried copying its app.config in case it was looking for it, but no luck. I also checked to make sure the configs were named correctly (<program>.exe.config).

Here's what I'm using. My console app creates an instance of JobSchdeuler and calls JobSchedulerConsoleStart.

Host Code:

public partial class JobScheduler : ServiceBase
{
    ServiceHost jobServiceHost = null;

    public JobScheduler()
    {
        ServiceName = "JobSchedulerService";
        InitializeComponent();
    }

    #region Service Init/Uninit

    /// <summary>
    /// OnStart
    /// </summary>
    /// <param name="args"></param>
    protected override void OnStart(string[] args)
    {
        if (jobServiceHost != null)
        {
            jobServiceHost.Close();
        }

        jobServiceHost = new ServiceHost(typeof(JobSchedulerWCF.JobService));

        jobServiceHost.Open();
    }

    /// <summary>
    /// OnStop
    /// </summary>
    protected override void OnStop()
    {
        if (jobServiceHost != null)
        {
            jobServiceHost.Close();
            jobServiceHost = null;
        }
    }

    #endregion

    #region Debugging

    public void JobSchedulerConsoleStart()
    {
        this.OnStart(null);
        Console.WriteLine("Service Started.");

        ProcessInput();

        Console.WriteLine("Service Stopped.");
        this.OnStop();
    }

    private void ProcessInput()
    {
        Console.WriteLine("Press any key to quit...");
        Console.ReadKey();
    }

    #endregion
}

app.config

<?xml version="1.0"?>
<configuration>
 <system.serviceModel>
  <services>
   <service behaviorConfiguration="JobSchedulerWCF.Service1Behavior" name="JobSchedulerWCF.JobService, JobSchedulerWCF">
    <endpoint address="" binding="wsHttpBinding" contract="JobSchedulerWCF.IJobServiceController, JobSchedulerWCF">
     <identity>
      <dns value="localhost" />
     </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
     <baseAddresses>
      <add baseAddress="http://localhost:12345/jobService"/&gt;
     </baseAddresses>
    </host>
   </service>
  </services>
  <behaviors>
   <serviceBehaviors>
    <behavior name="JobSchedulerWCF.Service1Behavior">
     <!-- To avoid disclosing metadata information, 
      set the value below to false and remove the metadata endpoint above before deployment -->
     <serviceMetadata httpGetEnabled="True"/>
     <!-- To receive exception details in faults for debugging purposes, 
       set the value below to true.  Set to false before deployment 
       to avoid disclosing exception information -->
     <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
 </system.serviceModel>   
</configuration>
A: 

Do your configuration files are named

  • Console.App.exe.config
  • Win.Service.exe.config

?

EDIT: If I remember correctly there was an issue with the Beta version of WCF and Service names.

Try to change

<service behaviorConfiguration="JobSchedulerWCF.Service1Behavior" name="JobSchedulerWCF.JobService, JobSchedulerWCF">

to

<service behaviorConfiguration="JobSchedulerWCF.Service1Behavior" name="JobSchedulerWCF.JobService">

Remove the assembly name in your config files.

Please let me know if that solves the problem. I didn't tied it.

Arthur
Yes they are. I've updated my post to include this.
Wes P
A: 

I never got to the bottom of this. There was something slightly off in the config/project. I rebuilt the solution and the problem went away.

Wes P