在Windows服务中托管WCF服务但未找到端点

时间:2014-07-02 17:44:21

标签: c# wcf windows-services

我有一个dulpex WCF服务,它托管在Windows服务中。我通过InstallUtil.exe从命令行安装了Windows服务,从服务管理面板启动服务。现在是时候测试WCF了。所以我添加了一个新的控制台项目作为客户端,下一步是添加Web项目的引用。 但是我收到了一个错误:

There was an error downloading `http://localhost:8733/KeyValueService/_vti_bin/ListData.svc/$metadata`.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:8733
Metadata contains a reference that cannot be resolved: `http://localhost:8733/KeyValueService`.

服务项目中的app.config有:

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="VoiceApp.KeyValueService">
    <endpoint address="http://localhost:8733/KeyValueService/" binding="wsDualHttpBinding" contract="VoiceApp.IService1" />
    <endpoint address="http://localhost:8733/KeyValueService/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<bindings>
  <basicHttpBinding>
  </basicHttpBinding>
</bindings>
<client>
</client>

我按照Metatata Exchange Endpoint Blog,进行了配置,但没有用。

同样在Windows服务中,我们有:

    protected override void OnStart(string[] args)
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
        }
        serviceHost = new ServiceHost(typeof(KeyValueService));
        serviceHost.Open();
        MyApplication.Start(); //  a long running code...
    }

更新

我的步骤是创建一个Windows服务项目,然后添加一个WCF服务。

1 个答案:

答案 0 :(得分:-1)

我知道这是一篇旧帖子,但我发现如果用端点的真实IP地址替换'localhost'可以解决这个问题。