【发布时间】:2013-05-12 10:28:54
【问题描述】:
我正在尝试启动 Windows 服务,但出现以下错误:
服务无法启动。 System.InvalidOperationException:服务 'LazyPCAndroiderSvc.LazyPCController' 的应用程序为零 (非基础设施)端点。这可能是因为没有配置 为您的应用程序找到了文件,或者因为没有服务元素 可以在配置文件中找到匹配的服务名称,或者 因为在服务元素中没有定义端点。
?
我已经使用 WCF Tester 测试了该服务,它没有造成任何问题。只有当我尝试将其作为 Windows 服务运行时,才会导致上述错误。
这是我来自 wcf 服务的 app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service name="LazyPCAndroiderSvc.LazyPCController"
behaviorConfiguration="LazyPCControllerBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8750/LazyPCAndroiderSvc/LazyPCController/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
contract="LazyPCAndroiderSvc.ILazyPCController" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="LazyPCControllerBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我已验证名称完全匹配(包括命名空间)。
这是我的 WindowsService 代码:
namespace LazyPCAndroiderWinSvc
{
public partial class Service : ServiceBase
{
ServiceHost sHost;
public Service()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
sHost = new ServiceHost(typeof(LazyPCAndroiderSvc.LazyPCController));
sHost.Open();
}
protected override void OnStop()
{
sHost.Close();
}
}
}
这似乎是一个微不足道的问题,但我找不到原因。
【问题讨论】:
-
服务指向的exe的路径是什么? .exe.config 是否存在于该位置?
-
@YK1 WCF 服务是作为参考加载的 VS 解决方案的一部分,因此它是一个 DLL。所有 LazyPCAndroiderSvc.dll、LazyPCAndroiderSvc.dll。 config,App.config 存在于 WCF 服务文件夹中。
标签: c# visual-studio-2010 wcf