我按照这篇MSDN文章彻底创建了托管在NT服务中的WCF服务.
当我在服务控制台中单击"开始"时,我在事件查看器中看到以下内容:
服务无法启动.System.InvalidOperationException:服务'MyServiceNamespace.RequestProcessorImpl'具有零应用程序(非基础结构)端点.这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在service元素中没有定义端点.
我试图检查我能找到的所有可能的原因.这是App.Config文件中的服务描述:
<service name="MyServiceNamespace.RequestProcessorWindowsService"
behaviorConfiguration="RequestProcessorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8095/RequestProcessorService"/>
</baseAddresses>
</host>
<endpoint address= ""
binding="wsHttpBinding"
contract="MyServiceNamespace.IRequestProcessor" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
Run Code Online (Sandbox Code Playgroud)
所有实体都以其命名空间命名,因此这不是问题所在.App.Config文件放在bin\Debug中 - 确切地说是NT服务的起始位置.
但是当我从原始实现中改变我的ServiceBase后代时OnStart():
public class RequestProcessorWindowsService : ServiceBase {
public ServiceHost serviceHost = null;
//other methods skipped
protected override void OnStart(string[] args)
{
if( serviceHost != null ) {
serviceHost.Close();
}
serviceHost = new ServiceHost( typeof(RequestProcesssorImpl) );
serviceHost.Open();
}
}
Run Code Online (Sandbox Code Playgroud)
到下一个,以便它调用AddServiceEndpoint()该服务开始没关系(但我不能添加它的引用,所以我猜其他问题):
public class RequestProcessorWindowsService : ServiceBase {
public ServiceHost serviceHost = null;
//other methods skipped
protected override void OnStart(string[] args)
{
if( serviceHost != null ) {
serviceHost.Close();
}
Uri baseAddress = new Uri("http://localhost:8095/RequestProcessorService");
serviceHost = new ServiceHost( typeof(RequestProcesssorImpl), baseAddress );
serviceHost.AddServiceEndpoint( typeof(IRequestProcessor), new BasicHttpBinding(), baseAddress );
serviceHost.Open();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我的服务在通过App.Config配置时没有启动?
Joh*_*ais 15
配置文件中的服务名称与服务实现类不匹配.
配置文件应包含:
<service name="MyServiceNamespace.RequestProcesssorImpl"
Run Code Online (Sandbox Code Playgroud)