【发布时间】:2013-12-27 13:14:26
【问题描述】:
在构建安装 Windows 服务后,当我尝试启动 Windows 服务时,出现第一个错误“Windows 无法在本地计算机上启动服务错误 5 访问被拒绝”。我按照以下解决方案解决了第一个错误:Cannot Start Windows Service in NetworkService account 。在此之后,第一个错误的通知消失了,但出现了另一个错误通知“本地计算机上的此服务启动然后停止。如果没有使用,某些服务会自动停止通过其他服务或程序”。我该如何解决这个问题?
注意: 我访问了许多发布的答案,但他们没有解决问题。
Windows service on Local Computer started and then stopped error
Windows 事件查看器通知:
Service cannot be started. System.InvalidOperationException: Service 'CustomerServiceLibrary.CustomersService' 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 WindowsServiceHost.WCFService.OnStart(String[] a...
已编辑:
namespace WindowsServiceHost
{
public partial class WCFService : ServiceBase
{
public WCFService()
{
InitializeComponent();
}
private ServiceHost host = null;
protected override void OnStart(string[] args)
{
System.Diagnostics.Debugger.Launch();
host = new ServiceHost(typeof(CustomersService));
host.Open();
}
protected override void OnStop()
{
if (host != null)
{
host.Close();
}
host = null;
}
}
}
app .config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
【问题讨论】:
-
您可以发布您的服务代码吗?您的代码中的某处可能会引发异常。你试过调试吗?
-
我正在关注“AppDev WCF_Using_C#_2008”的视频教程。他们只是在安装和启动之前构建它..
-
跟踪错误日志非常明显:没有为服务主机定义端点。您可以发布
app.config文件(或者是否在代码中生成端点?)
标签: c# .net wcf windows-services