【问题标题】:WCF Service start error - Service has zero application endpointsWCF 服务启动错误 - 服务有零个应用程序终结点
【发布时间】: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


【解决方案1】:

服务可能不会自动从 LazyPCAndroiderSvc.dll.config 读取 - 将这些配置放在您的主 exe 的 App.config 中

【讨论】:

  • 对不起,我有点困惑,你是说我需要将我的 LazyPCAndroiderSvc.dll.config 路径放入我的 Windows 服务 exe 配置中吗? (LazyPCAndroiderWinSvc)?我该怎么做呢?我找不到 Windows 服务的 app.config,它只存在于我的 WCF 服务中。
  • 您将 app.config 添加到您的 EXE 项目中。将dll.config的system.ServiceModel内容复制到exe.config中。
  • 哇,问题解决了!这很令人困惑,但它有效
  • 我做了一些更愚蠢的事情......我的 app.config 文件被命名为 app.cfg。导致了同样的错误,我花了一天的时间才找到它。
猜你喜欢
  • 2013-07-05
  • 2011-05-16
  • 1970-01-01
  • 2012-01-16
  • 2013-11-25
  • 1970-01-01
  • 2019-03-13
  • 2019-03-09
  • 1970-01-01
相关资源
最近更新 更多