Service has zero application (non-infrastructure)

2019-08-06 18:58发布

I'm aware to the fact that there are other questions with the same title. I tried their solutions to no avail.

I'm getting this message trying to start my service (Windows hosted) after registering it with installutil.
I have no experience with WCF, please be patient.

My service application is composed of two projects: Externals, where I have my service interface, client interface, data contracts and app.config, and Internals, that contains the service implementation (which is the host, the actual implementation is done in another file which doesn't inherit from my service interface, I'm not sure if it's a good practice or not).
My app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Internals.ExecutionService" behaviorConfiguration="Default">
        <endpoint name="TCPEndpoint" 
                  address="net.tcp://localhost:8080/ExecutionService" 
                  binding ="netTcpBinding" 
                  contract="Externals.IExecutionService"/>
        <endpoint address="mex" 
                  binding="mexTcpBinding" 
                  contract="IMetadataExhange"/>
        <host>
          <baseAddresses>
            <add baseAddress="netTcp://localhost:8080/ExecutionService"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

My interface:

using System.ServiceModel;

namespace Externals
{
    [ServiceContract(CallbackContract = typeof(IClientCallback))]
    public interface IExecutionService
    {
        /// <summary>
        /// Executes the mainflow.py file in the provided location.
        /// </summary>
        /// <param name="path">Path to the Python file.</param>
        /// <returns>Execution status. Expected to return Passed/Failed onlt.</returns>
        [OperationContract]
        ExecutionStatus Execute(string path);

        [OperationContract]
        ExecutionStatus GetStatus();
    }
}

and the implementation (which is really not ready yet, I'm just trying to see if I can get a client to add a service reference):

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
    public partial class ExecutionService : ServiceBase, IExecutionService
    {
        ServiceHost myHost;
        private IClientCallback callbackChannel;

        public ExecutionService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            myHost = new ServiceHost(typeof(ExecutionService));
            myHost.Open();
        }
}

And empty implementations for the interface.

The complete error:

Service cannot be started. System.InvalidOperationException: Service 'Internals.ExecutionService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
   at System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreApplicationEndpoints(ServiceDescription description)
   at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
   at System.ServiceModel.ServiceHostBase.InitializeRuntime()
   at System.ServiceModel.ServiceHostBase.OnBeginOpen()
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at Internals.ExecutionService.OnStart(String[] args) in C:\Users...

Taken from event viewer.

1条回答
手持菜刀,她持情操
2楼-- · 2019-08-06 19:43

Your app.config should be The internal's, not the external's. Rename it to Internals.exe.config (or whatever your "internals" exe is named) and put it in the same directory as your service exe.

查看更多
登录 后发表回答