[英]Host a WCF Service in a Windows Service but endpoint not found
我有一个dulpex WCF服务,该服务托管在Windows服务中。 我通过InstallUtil.exe从命令行安装Windows Service,然后从服务管理面板启动该服务。 现在该测试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服务。
我知道这是一篇旧文章,但是我发现,如果将“ localhost”替换为端点的真实IP地址,就可以解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.