在Windows服务中托管WCF服务,但未找到端点
本文关键字:服务 端点 WCF Windows | 更新日期: 2023-09-27 18:11:14
我有一个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服务。
我知道这是一个旧的帖子,但我发现,如果你用端点的真实IP地址代替'localhost'解决了这个问题。