我知道还有其他具有相同标题的问题。我尝试了他们的解决方案无济于事。
在使用installutil
.
我没有经验WCF
,请耐心等待。
我的服务应用程序由两个项目组成:Externals,其中有我的服务接口、客户端接口、数据协定和 app.config,以及 Internals,其中包含服务实现(即主机,实际实现在另一个文件中完成它不是从我的服务接口继承的,我不确定这是否是一个好习惯)。
我的 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>
我的界面:
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();
}
}
和实现(实际上还没有准备好,我只是想看看我是否可以让客户添加服务参考):
[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();
}
}
以及接口的空实现。
完整的错误:
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...
取自事件查看器。